ywana-core8 0.0.774 → 0.0.776
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +15 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +15 -15
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +15 -15
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/incubator/task.js +14 -11
package/package.json
CHANGED
package/src/incubator/task.js
CHANGED
@@ -38,8 +38,8 @@ export const TaskContextProvider = (props) => {
|
|
38
38
|
|
39
39
|
async function createTask(task, listener) {
|
40
40
|
try {
|
41
|
-
const
|
42
|
-
if (listener) addListener(
|
41
|
+
const newTask = await API.create(task);
|
42
|
+
if (listener) addListener(newTask.id, listener)
|
43
43
|
return response;
|
44
44
|
} catch (error) {
|
45
45
|
console.log("createTask error", error);
|
@@ -64,23 +64,26 @@ export const TaskContextProvider = (props) => {
|
|
64
64
|
}
|
65
65
|
}
|
66
66
|
|
67
|
-
function addListener(
|
68
|
-
_listeners[
|
67
|
+
function addListener(taskID, listener) {
|
68
|
+
_listeners[taskID] = listener
|
69
69
|
}
|
70
70
|
|
71
|
-
function removeListener(
|
72
|
-
delete _listeners[
|
71
|
+
function removeListener(taskID) {
|
72
|
+
delete _listeners[taskID]
|
73
73
|
}
|
74
74
|
|
75
75
|
useEffect(() => {
|
76
76
|
const interval = setInterval(async () => {
|
77
77
|
const tasks = await API.all()
|
78
78
|
|
79
|
-
//
|
80
|
-
|
81
|
-
const
|
82
|
-
if (
|
83
|
-
|
79
|
+
// find task for each listener
|
80
|
+
Object.keys(_listeners).forEach(taskID => {
|
81
|
+
const task = tasks.find(task => task.id === taskID)
|
82
|
+
if (task) {
|
83
|
+
const listener = _listeners[taskID]
|
84
|
+
if (listener) listener(task)
|
85
|
+
}
|
86
|
+
})
|
84
87
|
|
85
88
|
}, frequency)
|
86
89
|
return () => clearInterval(interval)
|