@rango-dev/queue-manager-react 0.1.10-next.69
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.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/provider.d.ts +15 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/queue-manager-react.cjs.development.js +79 -0
- package/dist/queue-manager-react.cjs.development.js.map +1 -0
- package/dist/queue-manager-react.cjs.production.min.js +2 -0
- package/dist/queue-manager-react.cjs.production.min.js.map +1 -0
- package/dist/queue-manager-react.esm.js +71 -0
- package/dist/queue-manager-react.esm.js.map +1 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +59 -0
- package/src/index.tsx +1 -0
- package/src/provider.tsx +99 -0
- package/src/types.ts +3 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { ManagerContext as Context, QueueDef, Events } from '@rango-dev/queue-manager-core';
|
|
3
|
+
import { ManagerContext } from './types';
|
|
4
|
+
interface PropTypes {
|
|
5
|
+
queuesDefs: QueueDef<any>[];
|
|
6
|
+
context: Context;
|
|
7
|
+
onPersistedDataLoaded?: Events['onPersistedDataLoaded'];
|
|
8
|
+
isPaused?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare function Provider(props: PropsWithChildren<PropTypes>): JSX.Element;
|
|
11
|
+
export declare function useManager(): {
|
|
12
|
+
manager: ManagerContext;
|
|
13
|
+
};
|
|
14
|
+
export default Provider;
|
|
15
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["src/provider.tsx"],"names":[],"mappings":"AAAA,OAAc,EAEZ,iBAAiB,EAOlB,MAAM,OAAO,CAAC;AACf,OAAO,EACL,cAAc,IAAI,OAAO,EAEzB,QAAQ,EACR,MAAM,EACP,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAMzC,UAAU,SAAS;IACjB,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,qBAAqB,CAAC,EAAE,MAAM,CAAC,uBAAuB,CAAC,CAAC;IACxD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,iBAAS,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAC,SAAS,CAAC,eA4DpD;AAED,wBAAgB,UAAU,IAAI;IAAE,OAAO,EAAE,cAAc,CAAA;CAAE,CAKxD;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
+
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var React__default = _interopDefault(React);
|
|
9
|
+
var queueManagerCore = require('@rango-dev/queue-manager-core');
|
|
10
|
+
|
|
11
|
+
var ManagerCtx = /*#__PURE__*/React.createContext({
|
|
12
|
+
manager: undefined
|
|
13
|
+
});
|
|
14
|
+
function Provider(props) {
|
|
15
|
+
// TODO: this is not a proper way but i don't want to change the context interface atm.
|
|
16
|
+
var _useState = React.useState({}),
|
|
17
|
+
forceRender = _useState[1];
|
|
18
|
+
var context = React.useRef(props.context);
|
|
19
|
+
var manager = React.useMemo(function () {
|
|
20
|
+
return new queueManagerCore.Manager({
|
|
21
|
+
queuesDefs: props.queuesDefs,
|
|
22
|
+
events: {
|
|
23
|
+
onStorageUpdate: function onStorageUpdate() {
|
|
24
|
+
forceRender({});
|
|
25
|
+
},
|
|
26
|
+
onCreateQueue: function onCreateQueue() {
|
|
27
|
+
forceRender({});
|
|
28
|
+
},
|
|
29
|
+
onCreateTask: function onCreateTask() {
|
|
30
|
+
forceRender({});
|
|
31
|
+
},
|
|
32
|
+
onUpdateQueue: function onUpdateQueue() {
|
|
33
|
+
forceRender({});
|
|
34
|
+
},
|
|
35
|
+
onUpdateTask: function onUpdateTask() {
|
|
36
|
+
forceRender({});
|
|
37
|
+
},
|
|
38
|
+
onPersistedDataLoaded: function onPersistedDataLoaded(manager) {
|
|
39
|
+
forceRender({});
|
|
40
|
+
if (props.onPersistedDataLoaded) {
|
|
41
|
+
props.onPersistedDataLoaded(manager);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
onTaskBlock: function onTaskBlock() {
|
|
45
|
+
forceRender({});
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
context: context || {},
|
|
49
|
+
isPaused: props.isPaused
|
|
50
|
+
});
|
|
51
|
+
}, []);
|
|
52
|
+
React.useLayoutEffect(function () {
|
|
53
|
+
context.current = props.context;
|
|
54
|
+
}, [props.context]);
|
|
55
|
+
React.useEffect(function () {
|
|
56
|
+
if (typeof props.isPaused !== 'undefined') {
|
|
57
|
+
if (props.isPaused) {
|
|
58
|
+
manager.pause();
|
|
59
|
+
} else {
|
|
60
|
+
manager.run();
|
|
61
|
+
}
|
|
62
|
+
forceRender({});
|
|
63
|
+
}
|
|
64
|
+
}, [props.isPaused]);
|
|
65
|
+
return React__default.createElement(ManagerCtx.Provider, {
|
|
66
|
+
value: {
|
|
67
|
+
manager: manager
|
|
68
|
+
}
|
|
69
|
+
}, props.children);
|
|
70
|
+
}
|
|
71
|
+
function useManager() {
|
|
72
|
+
var context = React.useContext(ManagerCtx);
|
|
73
|
+
if (!context) throw Error('useManager can only be used within the Provider component');
|
|
74
|
+
return context;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
exports.Provider = Provider;
|
|
78
|
+
exports.useManager = useManager;
|
|
79
|
+
//# sourceMappingURL=queue-manager-react.cjs.development.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-manager-react.cjs.development.js","sources":["../src/provider.tsx"],"sourcesContent":["import React, {\n createContext,\n PropsWithChildren,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport {\n ManagerContext as Context,\n Manager,\n QueueDef,\n Events,\n} from '@rango-dev/queue-manager-core';\nimport { ManagerContext } from './types';\n\nconst ManagerCtx = createContext<{ manager: ManagerContext }>({\n manager: undefined,\n});\n\ninterface PropTypes {\n queuesDefs: QueueDef<any>[];\n context: Context;\n onPersistedDataLoaded?: Events['onPersistedDataLoaded'];\n isPaused?: boolean;\n}\n\nfunction Provider(props: PropsWithChildren<PropTypes>) {\n // TODO: this is not a proper way but i don't want to change the context interface atm.\n const [, forceRender] = useState({});\n const context = useRef(props.context);\n\n const manager = useMemo<Manager>(() => {\n return new Manager({\n queuesDefs: props.queuesDefs,\n events: {\n onStorageUpdate: () => {\n forceRender({});\n },\n onCreateQueue: () => {\n forceRender({});\n },\n onCreateTask: () => {\n forceRender({});\n },\n onUpdateQueue: () => {\n forceRender({});\n },\n onUpdateTask: () => {\n forceRender({});\n },\n onPersistedDataLoaded: (manager) => {\n forceRender({});\n\n if (props.onPersistedDataLoaded) {\n props.onPersistedDataLoaded(manager);\n }\n },\n onTaskBlock: () => {\n forceRender({});\n },\n },\n context: context || {},\n isPaused: props.isPaused,\n });\n }, []);\n\n useLayoutEffect(() => {\n context.current = props.context;\n }, [props.context]);\n\n useEffect(() => {\n if (typeof props.isPaused !== 'undefined') {\n if (props.isPaused) {\n manager.pause();\n } else {\n manager.run();\n }\n forceRender({});\n }\n }, [props.isPaused]);\n\n return (\n <ManagerCtx.Provider value={{ manager }}>\n {props.children}\n </ManagerCtx.Provider>\n );\n}\n\nexport function useManager(): { manager: ManagerContext } {\n const context = useContext(ManagerCtx);\n if (!context)\n throw Error('useManager can only be used within the Provider component');\n return context;\n}\n\nexport default Provider;\n"],"names":["ManagerCtx","createContext","manager","undefined","Provider","props","useState","forceRender","context","useRef","useMemo","Manager","queuesDefs","events","onStorageUpdate","onCreateQueue","onCreateTask","onUpdateQueue","onUpdateTask","onPersistedDataLoaded","onTaskBlock","isPaused","useLayoutEffect","current","useEffect","pause","run","React","value","children","useManager","useContext","Error"],"mappings":";;;;;;;;;;AAkBA,IAAMA,UAAU,gBAAGC,mBAAa,CAA8B;EAC5DC,OAAO,EAAEC;CACV,CAAC;AASF,SAASC,QAAQ,CAACC,KAAmC;;EAEnD,gBAAwBC,cAAQ,CAAC,EAAE,CAAC;IAA3BC,WAAW;EACpB,IAAMC,OAAO,GAAGC,YAAM,CAACJ,KAAK,CAACG,OAAO,CAAC;EAErC,IAAMN,OAAO,GAAGQ,aAAO,CAAU;IAC/B,OAAO,IAAIC,wBAAO,CAAC;MACjBC,UAAU,EAAEP,KAAK,CAACO,UAAU;MAC5BC,MAAM,EAAE;QACNC,eAAe,EAAE;UACfP,WAAW,CAAC,EAAE,CAAC;SAChB;QACDQ,aAAa,EAAE;UACbR,WAAW,CAAC,EAAE,CAAC;SAChB;QACDS,YAAY,EAAE;UACZT,WAAW,CAAC,EAAE,CAAC;SAChB;QACDU,aAAa,EAAE;UACbV,WAAW,CAAC,EAAE,CAAC;SAChB;QACDW,YAAY,EAAE;UACZX,WAAW,CAAC,EAAE,CAAC;SAChB;QACDY,qBAAqB,EAAE,+BAACjB,OAAO;UAC7BK,WAAW,CAAC,EAAE,CAAC;UAEf,IAAIF,KAAK,CAACc,qBAAqB,EAAE;YAC/Bd,KAAK,CAACc,qBAAqB,CAACjB,OAAO,CAAC;;SAEvC;QACDkB,WAAW,EAAE;UACXb,WAAW,CAAC,EAAE,CAAC;;OAElB;MACDC,OAAO,EAAEA,OAAO,IAAI,EAAE;MACtBa,QAAQ,EAAEhB,KAAK,CAACgB;KACjB,CAAC;GACH,EAAE,EAAE,CAAC;EAENC,qBAAe,CAAC;IACdd,OAAO,CAACe,OAAO,GAAGlB,KAAK,CAACG,OAAO;GAChC,EAAE,CAACH,KAAK,CAACG,OAAO,CAAC,CAAC;EAEnBgB,eAAS,CAAC;IACR,IAAI,OAAOnB,KAAK,CAACgB,QAAQ,KAAK,WAAW,EAAE;MACzC,IAAIhB,KAAK,CAACgB,QAAQ,EAAE;QAClBnB,OAAO,CAACuB,KAAK,EAAE;OAChB,MAAM;QACLvB,OAAO,CAACwB,GAAG,EAAE;;MAEfnB,WAAW,CAAC,EAAE,CAAC;;GAElB,EAAE,CAACF,KAAK,CAACgB,QAAQ,CAAC,CAAC;EAEpB,OACEM,6BAAC3B,UAAU,CAACI,QAAQ;IAACwB,KAAK,EAAE;MAAE1B,OAAO,EAAPA;;KAC3BG,KAAK,CAACwB,QAAQ,CACK;AAE1B;SAEgBC,UAAU;EACxB,IAAMtB,OAAO,GAAGuB,gBAAU,CAAC/B,UAAU,CAAC;EACtC,IAAI,CAACQ,OAAO,EACV,MAAMwB,KAAK,CAAC,2DAA2D,CAAC;EAC1E,OAAOxB,OAAO;AAChB;;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,o=require("@rango-dev/queue-manager-core"),u=t.createContext({manager:void 0});exports.Provider=function(e){var a=t.useState({})[1],r=t.useRef(e.context),s=t.useMemo((function(){return new o.Manager({queuesDefs:e.queuesDefs,events:{onStorageUpdate:function(){a({})},onCreateQueue:function(){a({})},onCreateTask:function(){a({})},onUpdateQueue:function(){a({})},onUpdateTask:function(){a({})},onPersistedDataLoaded:function(t){a({}),e.onPersistedDataLoaded&&e.onPersistedDataLoaded(t)},onTaskBlock:function(){a({})}},context:r||{},isPaused:e.isPaused})}),[]);return t.useLayoutEffect((function(){r.current=e.context}),[e.context]),t.useEffect((function(){void 0!==e.isPaused&&(e.isPaused?s.pause():s.run(),a({}))}),[e.isPaused]),n.createElement(u.Provider,{value:{manager:s}},e.children)},exports.useManager=function(){var e=t.useContext(u);if(!e)throw Error("useManager can only be used within the Provider component");return e};
|
|
2
|
+
//# sourceMappingURL=queue-manager-react.cjs.production.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-manager-react.cjs.production.min.js","sources":["../src/provider.tsx"],"sourcesContent":["import React, {\n createContext,\n PropsWithChildren,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport {\n ManagerContext as Context,\n Manager,\n QueueDef,\n Events,\n} from '@rango-dev/queue-manager-core';\nimport { ManagerContext } from './types';\n\nconst ManagerCtx = createContext<{ manager: ManagerContext }>({\n manager: undefined,\n});\n\ninterface PropTypes {\n queuesDefs: QueueDef<any>[];\n context: Context;\n onPersistedDataLoaded?: Events['onPersistedDataLoaded'];\n isPaused?: boolean;\n}\n\nfunction Provider(props: PropsWithChildren<PropTypes>) {\n // TODO: this is not a proper way but i don't want to change the context interface atm.\n const [, forceRender] = useState({});\n const context = useRef(props.context);\n\n const manager = useMemo<Manager>(() => {\n return new Manager({\n queuesDefs: props.queuesDefs,\n events: {\n onStorageUpdate: () => {\n forceRender({});\n },\n onCreateQueue: () => {\n forceRender({});\n },\n onCreateTask: () => {\n forceRender({});\n },\n onUpdateQueue: () => {\n forceRender({});\n },\n onUpdateTask: () => {\n forceRender({});\n },\n onPersistedDataLoaded: (manager) => {\n forceRender({});\n\n if (props.onPersistedDataLoaded) {\n props.onPersistedDataLoaded(manager);\n }\n },\n onTaskBlock: () => {\n forceRender({});\n },\n },\n context: context || {},\n isPaused: props.isPaused,\n });\n }, []);\n\n useLayoutEffect(() => {\n context.current = props.context;\n }, [props.context]);\n\n useEffect(() => {\n if (typeof props.isPaused !== 'undefined') {\n if (props.isPaused) {\n manager.pause();\n } else {\n manager.run();\n }\n forceRender({});\n }\n }, [props.isPaused]);\n\n return (\n <ManagerCtx.Provider value={{ manager }}>\n {props.children}\n </ManagerCtx.Provider>\n );\n}\n\nexport function useManager(): { manager: ManagerContext } {\n const context = useContext(ManagerCtx);\n if (!context)\n throw Error('useManager can only be used within the Provider component');\n return context;\n}\n\nexport default Provider;\n"],"names":["ManagerCtx","createContext","manager","undefined","props","forceRender","useState","context","useRef","useMemo","Manager","queuesDefs","events","onStorageUpdate","onCreateQueue","onCreateTask","onUpdateQueue","onUpdateTask","onPersistedDataLoaded","onTaskBlock","isPaused","useLayoutEffect","current","useEffect","pause","run","React","Provider","value","children","useContext","Error"],"mappings":"+LAkBMA,EAAaC,gBAA2C,CAC5DC,aAASC,qBAUX,SAAkBC,GAEhB,IAASC,EAAeC,WAAS,OAC3BC,EAAUC,SAAOJ,EAAMG,SAEvBL,EAAUO,WAAiB,WAC/B,OAAO,IAAIC,UAAQ,CACjBC,WAAYP,EAAMO,WAClBC,OAAQ,CACNC,gBAAiB,WACfR,EAAY,KAEdS,cAAe,WACbT,EAAY,KAEdU,aAAc,WACZV,EAAY,KAEdW,cAAe,WACbX,EAAY,KAEdY,aAAc,WACZZ,EAAY,KAEda,sBAAuB,SAAChB,GACtBG,EAAY,IAERD,EAAMc,uBACRd,EAAMc,sBAAsBhB,IAGhCiB,YAAa,WACXd,EAAY,MAGhBE,QAASA,GAAW,GACpBa,SAAUhB,EAAMgB,aAEjB,IAiBH,OAfAC,mBAAgB,WACdd,EAAQe,QAAUlB,EAAMG,UACvB,CAACH,EAAMG,UAEVgB,aAAU,gBACsB,IAAnBnB,EAAMgB,WACXhB,EAAMgB,SACRlB,EAAQsB,QAERtB,EAAQuB,MAEVpB,EAAY,OAEb,CAACD,EAAMgB,WAGRM,gBAAC1B,EAAW2B,UAASC,MAAO,CAAE1B,QAAAA,IAC3BE,EAAMyB,yCAMX,IAAMtB,EAAUuB,aAAW9B,GAC3B,IAAKO,EACH,MAAMwB,MAAM,6DACd,OAAOxB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React, { useState, useRef, useMemo, useLayoutEffect, useEffect, useContext, createContext } from 'react';
|
|
2
|
+
import { Manager } from '@rango-dev/queue-manager-core';
|
|
3
|
+
|
|
4
|
+
var ManagerCtx = /*#__PURE__*/createContext({
|
|
5
|
+
manager: undefined
|
|
6
|
+
});
|
|
7
|
+
function Provider(props) {
|
|
8
|
+
// TODO: this is not a proper way but i don't want to change the context interface atm.
|
|
9
|
+
var _useState = useState({}),
|
|
10
|
+
forceRender = _useState[1];
|
|
11
|
+
var context = useRef(props.context);
|
|
12
|
+
var manager = useMemo(function () {
|
|
13
|
+
return new Manager({
|
|
14
|
+
queuesDefs: props.queuesDefs,
|
|
15
|
+
events: {
|
|
16
|
+
onStorageUpdate: function onStorageUpdate() {
|
|
17
|
+
forceRender({});
|
|
18
|
+
},
|
|
19
|
+
onCreateQueue: function onCreateQueue() {
|
|
20
|
+
forceRender({});
|
|
21
|
+
},
|
|
22
|
+
onCreateTask: function onCreateTask() {
|
|
23
|
+
forceRender({});
|
|
24
|
+
},
|
|
25
|
+
onUpdateQueue: function onUpdateQueue() {
|
|
26
|
+
forceRender({});
|
|
27
|
+
},
|
|
28
|
+
onUpdateTask: function onUpdateTask() {
|
|
29
|
+
forceRender({});
|
|
30
|
+
},
|
|
31
|
+
onPersistedDataLoaded: function onPersistedDataLoaded(manager) {
|
|
32
|
+
forceRender({});
|
|
33
|
+
if (props.onPersistedDataLoaded) {
|
|
34
|
+
props.onPersistedDataLoaded(manager);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
onTaskBlock: function onTaskBlock() {
|
|
38
|
+
forceRender({});
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
context: context || {},
|
|
42
|
+
isPaused: props.isPaused
|
|
43
|
+
});
|
|
44
|
+
}, []);
|
|
45
|
+
useLayoutEffect(function () {
|
|
46
|
+
context.current = props.context;
|
|
47
|
+
}, [props.context]);
|
|
48
|
+
useEffect(function () {
|
|
49
|
+
if (typeof props.isPaused !== 'undefined') {
|
|
50
|
+
if (props.isPaused) {
|
|
51
|
+
manager.pause();
|
|
52
|
+
} else {
|
|
53
|
+
manager.run();
|
|
54
|
+
}
|
|
55
|
+
forceRender({});
|
|
56
|
+
}
|
|
57
|
+
}, [props.isPaused]);
|
|
58
|
+
return React.createElement(ManagerCtx.Provider, {
|
|
59
|
+
value: {
|
|
60
|
+
manager: manager
|
|
61
|
+
}
|
|
62
|
+
}, props.children);
|
|
63
|
+
}
|
|
64
|
+
function useManager() {
|
|
65
|
+
var context = useContext(ManagerCtx);
|
|
66
|
+
if (!context) throw Error('useManager can only be used within the Provider component');
|
|
67
|
+
return context;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { Provider, useManager };
|
|
71
|
+
//# sourceMappingURL=queue-manager-react.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-manager-react.esm.js","sources":["../src/provider.tsx"],"sourcesContent":["import React, {\n createContext,\n PropsWithChildren,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport {\n ManagerContext as Context,\n Manager,\n QueueDef,\n Events,\n} from '@rango-dev/queue-manager-core';\nimport { ManagerContext } from './types';\n\nconst ManagerCtx = createContext<{ manager: ManagerContext }>({\n manager: undefined,\n});\n\ninterface PropTypes {\n queuesDefs: QueueDef<any>[];\n context: Context;\n onPersistedDataLoaded?: Events['onPersistedDataLoaded'];\n isPaused?: boolean;\n}\n\nfunction Provider(props: PropsWithChildren<PropTypes>) {\n // TODO: this is not a proper way but i don't want to change the context interface atm.\n const [, forceRender] = useState({});\n const context = useRef(props.context);\n\n const manager = useMemo<Manager>(() => {\n return new Manager({\n queuesDefs: props.queuesDefs,\n events: {\n onStorageUpdate: () => {\n forceRender({});\n },\n onCreateQueue: () => {\n forceRender({});\n },\n onCreateTask: () => {\n forceRender({});\n },\n onUpdateQueue: () => {\n forceRender({});\n },\n onUpdateTask: () => {\n forceRender({});\n },\n onPersistedDataLoaded: (manager) => {\n forceRender({});\n\n if (props.onPersistedDataLoaded) {\n props.onPersistedDataLoaded(manager);\n }\n },\n onTaskBlock: () => {\n forceRender({});\n },\n },\n context: context || {},\n isPaused: props.isPaused,\n });\n }, []);\n\n useLayoutEffect(() => {\n context.current = props.context;\n }, [props.context]);\n\n useEffect(() => {\n if (typeof props.isPaused !== 'undefined') {\n if (props.isPaused) {\n manager.pause();\n } else {\n manager.run();\n }\n forceRender({});\n }\n }, [props.isPaused]);\n\n return (\n <ManagerCtx.Provider value={{ manager }}>\n {props.children}\n </ManagerCtx.Provider>\n );\n}\n\nexport function useManager(): { manager: ManagerContext } {\n const context = useContext(ManagerCtx);\n if (!context)\n throw Error('useManager can only be used within the Provider component');\n return context;\n}\n\nexport default Provider;\n"],"names":["ManagerCtx","createContext","manager","undefined","Provider","props","useState","forceRender","context","useRef","useMemo","Manager","queuesDefs","events","onStorageUpdate","onCreateQueue","onCreateTask","onUpdateQueue","onUpdateTask","onPersistedDataLoaded","onTaskBlock","isPaused","useLayoutEffect","current","useEffect","pause","run","React","value","children","useManager","useContext","Error"],"mappings":";;;AAkBA,IAAMA,UAAU,gBAAGC,aAAa,CAA8B;EAC5DC,OAAO,EAAEC;CACV,CAAC;AASF,SAASC,QAAQ,CAACC,KAAmC;;EAEnD,gBAAwBC,QAAQ,CAAC,EAAE,CAAC;IAA3BC,WAAW;EACpB,IAAMC,OAAO,GAAGC,MAAM,CAACJ,KAAK,CAACG,OAAO,CAAC;EAErC,IAAMN,OAAO,GAAGQ,OAAO,CAAU;IAC/B,OAAO,IAAIC,OAAO,CAAC;MACjBC,UAAU,EAAEP,KAAK,CAACO,UAAU;MAC5BC,MAAM,EAAE;QACNC,eAAe,EAAE;UACfP,WAAW,CAAC,EAAE,CAAC;SAChB;QACDQ,aAAa,EAAE;UACbR,WAAW,CAAC,EAAE,CAAC;SAChB;QACDS,YAAY,EAAE;UACZT,WAAW,CAAC,EAAE,CAAC;SAChB;QACDU,aAAa,EAAE;UACbV,WAAW,CAAC,EAAE,CAAC;SAChB;QACDW,YAAY,EAAE;UACZX,WAAW,CAAC,EAAE,CAAC;SAChB;QACDY,qBAAqB,EAAE,+BAACjB,OAAO;UAC7BK,WAAW,CAAC,EAAE,CAAC;UAEf,IAAIF,KAAK,CAACc,qBAAqB,EAAE;YAC/Bd,KAAK,CAACc,qBAAqB,CAACjB,OAAO,CAAC;;SAEvC;QACDkB,WAAW,EAAE;UACXb,WAAW,CAAC,EAAE,CAAC;;OAElB;MACDC,OAAO,EAAEA,OAAO,IAAI,EAAE;MACtBa,QAAQ,EAAEhB,KAAK,CAACgB;KACjB,CAAC;GACH,EAAE,EAAE,CAAC;EAENC,eAAe,CAAC;IACdd,OAAO,CAACe,OAAO,GAAGlB,KAAK,CAACG,OAAO;GAChC,EAAE,CAACH,KAAK,CAACG,OAAO,CAAC,CAAC;EAEnBgB,SAAS,CAAC;IACR,IAAI,OAAOnB,KAAK,CAACgB,QAAQ,KAAK,WAAW,EAAE;MACzC,IAAIhB,KAAK,CAACgB,QAAQ,EAAE;QAClBnB,OAAO,CAACuB,KAAK,EAAE;OAChB,MAAM;QACLvB,OAAO,CAACwB,GAAG,EAAE;;MAEfnB,WAAW,CAAC,EAAE,CAAC;;GAElB,EAAE,CAACF,KAAK,CAACgB,QAAQ,CAAC,CAAC;EAEpB,OACEM,oBAAC3B,UAAU,CAACI,QAAQ;IAACwB,KAAK,EAAE;MAAE1B,OAAO,EAAPA;;KAC3BG,KAAK,CAACwB,QAAQ,CACK;AAE1B;SAEgBC,UAAU;EACxB,IAAMtB,OAAO,GAAGuB,UAAU,CAAC/B,UAAU,CAAC;EACtC,IAAI,CAACQ,OAAO,EACV,MAAMwB,KAAK,CAAC,2DAA2D,CAAC;EAC1E,OAAOxB,OAAO;AAChB;;;;"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAExD,oBAAY,cAAc,GAAG,OAAO,GAAG,SAAS,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.1.10-next.69",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"typings": "dist/index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"src"
|
|
9
|
+
],
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=10"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"dev": "tsdx watch",
|
|
15
|
+
"build": "tsdx build",
|
|
16
|
+
"test": "tsdx test --passWithNoTests",
|
|
17
|
+
"lint": "tsdx lint",
|
|
18
|
+
"size": "size-limit",
|
|
19
|
+
"analyze": "size-limit --why"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@rango-dev/queue-manager-core": "*",
|
|
23
|
+
"@types/react": "^17.0.0 || ^18.0.0",
|
|
24
|
+
"react": "^17.0.0 || ^18.0.0",
|
|
25
|
+
"react-dom": "^17.0.0 || ^18.0.0"
|
|
26
|
+
},
|
|
27
|
+
"husky": {
|
|
28
|
+
"hooks": {
|
|
29
|
+
"pre-commit": "tsdx lint"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"prettier": {
|
|
33
|
+
"printWidth": 80,
|
|
34
|
+
"semi": true,
|
|
35
|
+
"singleQuote": true,
|
|
36
|
+
"trailingComma": "es5"
|
|
37
|
+
},
|
|
38
|
+
"name": "@rango-dev/queue-manager-react",
|
|
39
|
+
"author": "mojtabast",
|
|
40
|
+
"module": "dist/queue-manager-react.esm.js",
|
|
41
|
+
"size-limit": [
|
|
42
|
+
{
|
|
43
|
+
"path": "dist/queue-manager-react.cjs.production.min.js",
|
|
44
|
+
"limit": "10 KB"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"path": "dist/queue-manager-react.esm.js",
|
|
48
|
+
"limit": "10 KB"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"react": "^18.2.0",
|
|
53
|
+
"react-dom": "^18.2.0"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
},
|
|
58
|
+
"gitHead": "35fad4db1d491a9589a8215b0c4a4e2f541d07f2"
|
|
59
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Provider, useManager } from './provider';
|
package/src/provider.tsx
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
createContext,
|
|
3
|
+
PropsWithChildren,
|
|
4
|
+
useContext,
|
|
5
|
+
useEffect,
|
|
6
|
+
useLayoutEffect,
|
|
7
|
+
useMemo,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
} from 'react';
|
|
11
|
+
import {
|
|
12
|
+
ManagerContext as Context,
|
|
13
|
+
Manager,
|
|
14
|
+
QueueDef,
|
|
15
|
+
Events,
|
|
16
|
+
} from '@rango-dev/queue-manager-core';
|
|
17
|
+
import { ManagerContext } from './types';
|
|
18
|
+
|
|
19
|
+
const ManagerCtx = createContext<{ manager: ManagerContext }>({
|
|
20
|
+
manager: undefined,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
interface PropTypes {
|
|
24
|
+
queuesDefs: QueueDef<any>[];
|
|
25
|
+
context: Context;
|
|
26
|
+
onPersistedDataLoaded?: Events['onPersistedDataLoaded'];
|
|
27
|
+
isPaused?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function Provider(props: PropsWithChildren<PropTypes>) {
|
|
31
|
+
// TODO: this is not a proper way but i don't want to change the context interface atm.
|
|
32
|
+
const [, forceRender] = useState({});
|
|
33
|
+
const context = useRef(props.context);
|
|
34
|
+
|
|
35
|
+
const manager = useMemo<Manager>(() => {
|
|
36
|
+
return new Manager({
|
|
37
|
+
queuesDefs: props.queuesDefs,
|
|
38
|
+
events: {
|
|
39
|
+
onStorageUpdate: () => {
|
|
40
|
+
forceRender({});
|
|
41
|
+
},
|
|
42
|
+
onCreateQueue: () => {
|
|
43
|
+
forceRender({});
|
|
44
|
+
},
|
|
45
|
+
onCreateTask: () => {
|
|
46
|
+
forceRender({});
|
|
47
|
+
},
|
|
48
|
+
onUpdateQueue: () => {
|
|
49
|
+
forceRender({});
|
|
50
|
+
},
|
|
51
|
+
onUpdateTask: () => {
|
|
52
|
+
forceRender({});
|
|
53
|
+
},
|
|
54
|
+
onPersistedDataLoaded: (manager) => {
|
|
55
|
+
forceRender({});
|
|
56
|
+
|
|
57
|
+
if (props.onPersistedDataLoaded) {
|
|
58
|
+
props.onPersistedDataLoaded(manager);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
onTaskBlock: () => {
|
|
62
|
+
forceRender({});
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
context: context || {},
|
|
66
|
+
isPaused: props.isPaused,
|
|
67
|
+
});
|
|
68
|
+
}, []);
|
|
69
|
+
|
|
70
|
+
useLayoutEffect(() => {
|
|
71
|
+
context.current = props.context;
|
|
72
|
+
}, [props.context]);
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (typeof props.isPaused !== 'undefined') {
|
|
76
|
+
if (props.isPaused) {
|
|
77
|
+
manager.pause();
|
|
78
|
+
} else {
|
|
79
|
+
manager.run();
|
|
80
|
+
}
|
|
81
|
+
forceRender({});
|
|
82
|
+
}
|
|
83
|
+
}, [props.isPaused]);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<ManagerCtx.Provider value={{ manager }}>
|
|
87
|
+
{props.children}
|
|
88
|
+
</ManagerCtx.Provider>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function useManager(): { manager: ManagerContext } {
|
|
93
|
+
const context = useContext(ManagerCtx);
|
|
94
|
+
if (!context)
|
|
95
|
+
throw Error('useManager can only be used within the Provider component');
|
|
96
|
+
return context;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export default Provider;
|
package/src/types.ts
ADDED