ywana-core8 0.0.832 → 0.0.834
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/db/db.json +3 -3
- package/dist/index.cjs +8 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +8 -6
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +8 -5
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/domain/index.js +1 -0
- package/src/incubator/task-test.js +25 -12
- package/src/incubator/task.js +5 -5
package/package.json
CHANGED
package/src/domain/index.js
CHANGED
@@ -4,6 +4,7 @@ export { ContentEditor, TabbedContentEditor, CollectionEditor, TreededContentEdi
|
|
4
4
|
export { ContentViewer } from './ContentViewer'
|
5
5
|
export { CreateContentDialog } from './CreateContentDialog'
|
6
6
|
export { EditContentDialog } from './EditContentDialog'
|
7
|
+
export { CollectionAPI } from './CollectionAPI'
|
7
8
|
export { CollectionPage, CollectionContext, CollectionTree, CollectionFilters } from './CollectionPage'
|
8
9
|
export { TablePage, TableEditor } from './TablePage'
|
9
10
|
export { TablePage2 } from './TablePage2'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { useContext, useState } from "react"
|
2
2
|
import { Button } from "../html"
|
3
|
-
import { TaskContext, TaskContextProvider, TaskMonitor } from "./task"
|
3
|
+
import { TaskContext, TaskContextProvider, TaskMonitor, TASK_STATES } from "./task"
|
4
4
|
|
5
5
|
/**
|
6
6
|
* Task Example
|
@@ -35,11 +35,31 @@ const CreateTaskButton = (props) => {
|
|
35
35
|
const taskContext = useContext(TaskContext)
|
36
36
|
|
37
37
|
async function run() {
|
38
|
-
|
38
|
+
|
39
|
+
const listener = async (task, taskContext) => {
|
40
|
+
|
41
|
+
console.log("LISTENER FOR TASK: ", task)
|
42
|
+
|
43
|
+
if (task.percentage === 100) {
|
44
|
+
console.log("TASK COMPLETED: ", task)
|
45
|
+
taskContext.updateTask(Object.assign({}, task, { state: TASK_STATES.COMPLETED }))
|
46
|
+
taskContext.removeListener(task.id)
|
47
|
+
} else {
|
48
|
+
const percentage = task.percentage + 10 || 0
|
49
|
+
const nextTask = Object.assign({}, task, { percentage })
|
50
|
+
await taskContext.updateTask(nextTask)
|
51
|
+
}
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
await taskContext.createTask({
|
39
56
|
name: "TEST",
|
40
57
|
description: "Test Task " + Date.now(),
|
41
58
|
result: "OK",
|
42
|
-
|
59
|
+
percentage: 0
|
60
|
+
}, listener)
|
61
|
+
|
62
|
+
return
|
43
63
|
}
|
44
64
|
|
45
65
|
return (
|
@@ -50,20 +70,13 @@ const CreateTaskButton = (props) => {
|
|
50
70
|
|
51
71
|
const TaskTest = (props) => {
|
52
72
|
|
53
|
-
const taskListeners = {
|
54
|
-
"TEST": (task, taskContext) => {
|
55
|
-
console.log("LISTENER FOR TASK: ", task)
|
56
|
-
taskContext.updateTask(Object.assign({}, task, { percentage: task.percentage + 1 }))
|
57
|
-
}
|
58
|
-
}
|
59
|
-
|
60
73
|
const taskEditors = {
|
61
74
|
"TEST": (task) => <div>{task.description} {task.state}</div>,
|
62
75
|
}
|
63
76
|
|
64
77
|
return (
|
65
|
-
<TaskContextProvider host="http://localhost:
|
66
|
-
<TaskMonitor editors={taskEditors} from="2023-10-21"/>
|
78
|
+
<TaskContextProvider host="http://localhost:3000" frequency={1000}>
|
79
|
+
<TaskMonitor editors={taskEditors} from="2023-10-21" frequency={2000}/>
|
67
80
|
<CreateTaskButton />
|
68
81
|
</TaskContextProvider>
|
69
82
|
)
|
package/src/incubator/task.js
CHANGED
@@ -78,10 +78,10 @@ export const TaskContextProvider = (props) => {
|
|
78
78
|
if (taskIDs.length === 0) return
|
79
79
|
for (let i = 0; i < taskIDs.length; i++) {
|
80
80
|
const taskID = taskIDs[i]
|
81
|
-
const
|
82
|
-
if (
|
81
|
+
const tsk = await task(taskID)
|
82
|
+
if (tsk) {
|
83
83
|
const listener = _listeners[taskID]
|
84
|
-
if (listener) listener(
|
84
|
+
if (listener) listener(tsk, value)
|
85
85
|
}
|
86
86
|
}
|
87
87
|
}, frequency)
|
@@ -149,7 +149,7 @@ export const TaskProgress = (props) => {
|
|
149
149
|
*/
|
150
150
|
export const TaskMonitor = (props) => {
|
151
151
|
|
152
|
-
const { title = "Task Monitor", filters = {}, editors } = props
|
152
|
+
const { title = "Task Monitor", filters = {}, editors, frequency = 5000 } = props
|
153
153
|
const context = useContext(TaskContext)
|
154
154
|
const [tasks = [], setTasks] = useState([])
|
155
155
|
|
@@ -157,7 +157,7 @@ export const TaskMonitor = (props) => {
|
|
157
157
|
refresh()
|
158
158
|
const interval = setInterval(() => {
|
159
159
|
refresh()
|
160
|
-
},
|
160
|
+
}, frequency)
|
161
161
|
return () => { clearInterval(interval) }
|
162
162
|
}, [])
|
163
163
|
|