Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
flowagent
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
node-red
flowagent
Commits
936fad75
Commit
936fad75
authored
Apr 19, 2020
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change toicstore from promise to return
parent
b163fa47
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
52 deletions
+49
-52
spec/topicstore.js
+26
-26
topicstore.js
+23
-26
No files found.
spec/topicstore.js
View file @
936fad75
...
@@ -18,49 +18,49 @@ describe("Test TopicStore", function () {
...
@@ -18,49 +18,49 @@ describe("Test TopicStore", function () {
done
();
done
();
});
});
it
(
"After addTopic(), topicstore should hold that topic"
,
async
function
()
{
it
(
"After addTopic(), topicstore should hold that topic"
,
function
()
{
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
getTopics
()).
to
.
deep
.
equal
([
'@msg/hello'
]);
expect
(
topicstore
.
getTopics
()).
to
.
deep
.
equal
([
'@msg/hello'
]);
});
});
it
(
"If add duplicate topics, topicstore.addTopic() should return false"
,
async
function
()
{
it
(
"If add duplicate topics, topicstore.addTopic() should return false"
,
function
()
{
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
false
);
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
false
);
expect
(
topicstore
.
getTopics
()).
to
.
deep
.
equal
([
'@msg/hello'
]);
expect
(
topicstore
.
getTopics
()).
to
.
deep
.
equal
([
'@msg/hello'
]);
});
});
it
(
"If add more topics, topicstore.addTopic() should hold all"
,
async
function
()
{
it
(
"If add more topics, topicstore.addTopic() should hold all"
,
function
()
{
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
await
topicstore
.
addTopic
(
'@msg/ok'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
addTopic
(
'@msg/ok'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
await
topicstore
.
addTopic
(
'@msg/bye'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
addTopic
(
'@msg/bye'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
getTopics
()).
to
.
deep
.
equal
([
'@msg/hello'
,
'@msg/ok'
,
'@msg/bye'
]);
expect
(
topicstore
.
getTopics
()).
to
.
deep
.
equal
([
'@msg/hello'
,
'@msg/ok'
,
'@msg/bye'
]);
});
});
it
(
"If add duplicate topics by different block, topicstore.addTopic() should return false"
,
async
function
()
{
it
(
"If add duplicate topics by different block, topicstore.addTopic() should return false"
,
function
()
{
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
false
);
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
false
);
expect
(
topicstore
.
getTopics
()).
to
.
deep
.
equal
([
'@msg/hello'
]);
expect
(
topicstore
.
getTopics
()).
to
.
deep
.
equal
([
'@msg/hello'
]);
});
});
it
(
"topicstore.delTopic() should return true if one block holds that topic"
,
async
function
()
{
it
(
"topicstore.delTopic() should return true if one block holds that topic"
,
function
()
{
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
expect
(
await
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
});
});
it
(
"topicstore.delTopic() should return false if two block holds that topic"
,
async
function
()
{
it
(
"topicstore.delTopic() should return false if two block holds that topic"
,
function
()
{
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
false
);
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
false
);
expect
(
await
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
false
);
expect
(
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
false
);
});
});
it
(
"topicstore.delTopic() should return true only if delete by the last block holding that topic"
,
async
function
()
{
it
(
"topicstore.delTopic() should return true only if delete by the last block holding that topic"
,
function
()
{
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
false
);
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
false
);
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.9012'
)).
to
.
equal
(
false
);
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.9012'
)).
to
.
equal
(
false
);
expect
(
await
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.9012'
)).
to
.
equal
(
false
);
expect
(
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.9012'
)).
to
.
equal
(
false
);
expect
(
await
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
false
);
expect
(
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
false
);
expect
(
await
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
true
);
});
});
...
...
topicstore.js
View file @
936fad75
...
@@ -23,41 +23,38 @@ TopicStore.prototype.getRawData = function() {
...
@@ -23,41 +23,38 @@ TopicStore.prototype.getRawData = function() {
}
}
TopicStore
.
prototype
.
addTopic
=
function
(
topic
,
blockid
)
{
TopicStore
.
prototype
.
addTopic
=
function
(
topic
,
blockid
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
this
.
data
[
topic
]
==
undefined
||
this
.
data
[
topic
].
length
==
0
)
{
if
(
this
.
data
[
topic
]
==
undefined
||
this
.
data
[
topic
].
length
==
0
)
{
this
.
data
[
topic
]
=
[
blockid
];
this
.
data
[
topic
]
=
[
blockid
];
return
(
true
)
resolve
(
true
)
}
else
{
let
p
=
this
.
data
[
topic
].
indexOf
(
blockid
);
if
(
p
>=
0
)
{
return
(
false
);
}
}
else
{
else
{
let
p
=
this
.
data
[
topic
].
indexOf
(
blockid
);
this
.
data
[
topic
].
push
(
blockid
);
if
(
p
>=
0
)
{
return
(
false
)
resolve
(
false
);
}
else
{
this
.
data
[
topic
].
push
(
blockid
);
resolve
(
false
)
}
}
}
});
}
}
}
TopicStore
.
prototype
.
delTopic
=
function
(
topic
,
blockid
)
{
TopicStore
.
prototype
.
delTopic
=
function
(
topic
,
blockid
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
this
.
data
[
topic
]
==
undefined
||
this
.
data
[
topic
].
length
==
0
)
{
if
(
this
.
data
[
topic
]
==
undefined
||
this
.
data
[
topic
].
length
==
0
)
{
return
(
true
);
// still force unsub
resolve
(
true
);
// still force unsub
}
else
{
let
p
=
this
.
data
[
topic
].
indexOf
(
blockid
);
if
(
p
>=
0
)
{
this
.
data
[
topic
].
splice
(
p
,
1
);
if
(
this
.
data
[
topic
].
length
==
0
)
return
(
true
);
else
return
(
false
);
}
}
else
{
else
{
let
p
=
this
.
data
[
topic
].
indexOf
(
blockid
);
return
(
false
);
if
(
p
>=
0
)
{
this
.
data
[
topic
].
splice
(
p
,
1
);
if
(
this
.
data
[
topic
].
length
==
0
)
resolve
(
true
);
else
resolve
(
false
);
}
else
{
resolve
(
false
);
}
}
}
}
);
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment