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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ywana-core8",
3
- "version": "0.0.774",
3
+ "version": "0.0.776",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -38,8 +38,8 @@ export const TaskContextProvider = (props) => {
38
38
 
39
39
  async function createTask(task, listener) {
40
40
  try {
41
- const response = await API.create(task);
42
- if (listener) addListener(task.name || task.action, listener)
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(taskName, listener) {
68
- _listeners[taskName] = listener
67
+ function addListener(taskID, listener) {
68
+ _listeners[taskID] = listener
69
69
  }
70
70
 
71
- function removeListener(taskName) {
72
- delete _listeners[taskName]
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
- // invoque listener for each task
80
- tasks.forEach(task => {
81
- const listener = _listeners[task.name || task.action]
82
- if (listener) listener(task)
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)