@modern-js/plugin 1.3.8 → 1.4.1

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/js/modern/farrow-pipeline/context.js +14 -75
  3. package/dist/js/modern/farrow-pipeline/index.js +0 -14
  4. package/dist/js/modern/farrow-pipeline/pipeline.js +12 -29
  5. package/dist/js/modern/manager/async.js +8 -12
  6. package/dist/js/modern/manager/index.js +0 -1
  7. package/dist/js/modern/manager/sync.js +13 -19
  8. package/dist/js/modern/waterfall/async.js +1 -3
  9. package/dist/js/modern/waterfall/sync.js +1 -3
  10. package/dist/js/modern/workflow/async.js +3 -3
  11. package/dist/js/modern/workflow/parallel.js +2 -2
  12. package/dist/js/modern/workflow/sync.js +3 -3
  13. package/dist/js/node/farrow-pipeline/context.js +15 -88
  14. package/dist/js/node/farrow-pipeline/pipeline.js +10 -45
  15. package/dist/js/node/manager/async.js +10 -16
  16. package/dist/js/node/manager/index.js +0 -13
  17. package/dist/js/node/manager/sync.js +16 -23
  18. package/dist/js/node/waterfall/async.js +0 -2
  19. package/dist/js/node/waterfall/sync.js +0 -2
  20. package/dist/js/node/workflow/async.js +3 -3
  21. package/dist/js/node/workflow/parallel.js +2 -2
  22. package/dist/js/node/workflow/sync.js +3 -3
  23. package/dist/js/treeshaking/farrow-pipeline/context.js +14 -75
  24. package/dist/js/treeshaking/farrow-pipeline/index.js +0 -14
  25. package/dist/js/treeshaking/farrow-pipeline/pipeline.js +10 -29
  26. package/dist/js/treeshaking/manager/async.js +15 -17
  27. package/dist/js/treeshaking/manager/index.js +0 -1
  28. package/dist/js/treeshaking/manager/sync.js +16 -20
  29. package/dist/js/treeshaking/waterfall/async.js +1 -3
  30. package/dist/js/treeshaking/waterfall/sync.js +1 -3
  31. package/dist/js/treeshaking/workflow/async.js +6 -6
  32. package/dist/js/treeshaking/workflow/parallel.js +5 -5
  33. package/dist/js/treeshaking/workflow/sync.js +3 -3
  34. package/dist/types/farrow-pipeline/context.d.ts +5 -20
  35. package/dist/types/farrow-pipeline/index.d.ts +0 -14
  36. package/dist/types/farrow-pipeline/pipeline.d.ts +5 -14
  37. package/dist/types/manager/async.d.ts +4 -7
  38. package/dist/types/manager/index.d.ts +0 -1
  39. package/dist/types/manager/sync.d.ts +6 -10
  40. package/dist/types/manager/types.d.ts +1 -6
  41. package/dist/types/waterfall/async.d.ts +1 -7
  42. package/dist/types/waterfall/sync.d.ts +0 -7
  43. package/dist/types/workflow/async.d.ts +1 -7
  44. package/dist/types/workflow/parallel.d.ts +2 -9
  45. package/dist/types/workflow/sync.d.ts +1 -10
  46. package/package.json +1 -12
  47. package/dist/js/modern/farrow-pipeline/asyncHooks.node.js +0 -80
  48. package/dist/js/modern/farrow-pipeline/asyncHooksInterface.js +0 -12
  49. package/dist/js/modern/farrow-pipeline/hook.js +0 -42
  50. package/dist/js/modern/manager/runner.js +0 -11
  51. package/dist/js/node/farrow-pipeline/asyncHooks.node.js +0 -100
  52. package/dist/js/node/farrow-pipeline/asyncHooksInterface.js +0 -26
  53. package/dist/js/node/farrow-pipeline/hook.js +0 -52
  54. package/dist/js/node/manager/runner.js +0 -23
  55. package/dist/js/treeshaking/farrow-pipeline/asyncHooks.node.js +0 -80
  56. package/dist/js/treeshaking/farrow-pipeline/asyncHooksInterface.js +0 -12
  57. package/dist/js/treeshaking/farrow-pipeline/hook.js +0 -46
  58. package/dist/js/treeshaking/manager/runner.js +0 -11
  59. package/dist/types/farrow-pipeline/asyncHooks.node.d.ts +0 -2
  60. package/dist/types/farrow-pipeline/asyncHooksInterface.d.ts +0 -19
  61. package/dist/types/farrow-pipeline/hook.d.ts +0 -9
  62. package/dist/types/manager/runner.d.ts +0 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @modern-js/plugin
2
2
 
3
+ ## 1.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f29e9ba: feat(plugin): simplify context usage, no longer depend on containers
8
+
3
9
  ## 1.3.8
4
10
 
5
11
  ### Patch Changes
@@ -2,39 +2,30 @@
2
2
  * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
3
  * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
4
  */
5
- import { createHooks } from "./hook";
6
- const ContextSymbol = Symbol.for('MODERN_CONTEXT');
7
5
  export const createContext = value => {
8
- const id = Symbol('MODERN_CONTEXT_ID');
6
+ let currentValue;
9
7
 
10
8
  const create = value => {
11
- const use = () => {
12
- const container = useContainer();
13
- return Object.seal({
14
- get value() {
15
- return container.read(Context);
16
- },
9
+ currentValue = value;
17
10
 
18
- set value(v) {
19
- container.write(Context, v);
20
- }
11
+ const use = () => ({
12
+ get value() {
13
+ return currentValue;
14
+ },
21
15
 
22
- });
23
- };
16
+ set value(v) {
17
+ currentValue = v;
18
+ }
24
19
 
25
- const get = () => {
26
- const container = useContainer();
27
- return container.read(Context);
28
- };
20
+ });
21
+
22
+ const get = () => currentValue;
29
23
 
30
24
  const set = v => {
31
- const container = useContainer();
32
- container.write(Context, v);
25
+ currentValue = v;
33
26
  };
34
27
 
35
28
  const Context = {
36
- id,
37
- [ContextSymbol]: value,
38
29
  create,
39
30
  use,
40
31
  get,
@@ -44,56 +35,4 @@ export const createContext = value => {
44
35
  };
45
36
 
46
37
  return create(value);
47
- };
48
-
49
- const createContextMap = storage => {
50
- const contextMap = new Map();
51
- const contexts = Object.values(storage); // eslint-disable-next-line @typescript-eslint/prefer-for-of
52
-
53
- for (let i = 0; i < contexts.length; i++) {
54
- contextMap.set(contexts[i].id, contexts[i]);
55
- }
56
-
57
- return contextMap;
58
- };
59
-
60
- export const createContainer = (ContextStorage = {}) => {
61
- const contextMap = createContextMap(ContextStorage);
62
-
63
- const read = context => {
64
- const target = contextMap.get(context.id);
65
-
66
- if (target) {
67
- return target[ContextSymbol];
68
- }
69
-
70
- return context[ContextSymbol];
71
- };
72
-
73
- const write = (context, value) => {
74
- contextMap.set(context.id, context.create(value));
75
- };
76
-
77
- return Object.freeze({
78
- read,
79
- write
80
- });
81
- };
82
- const {
83
- run,
84
- hooks
85
- } = createHooks({
86
- useContainer: () => {
87
- throw new Error(`Can't call useContainer out of scope, it should be placed on top of the function`);
88
- }
89
- });
90
- export const runHooks = run;
91
- export const {
92
- useContainer
93
- } = hooks;
94
- export const fromContainer = container => ({
95
- useContainer: () => {
96
- return container;
97
- }
98
- });
99
- export const runWithContainer = (f, container) => runHooks(f, fromContainer(container));
38
+ };
@@ -1,19 +1,5 @@
1
1
  /**
2
2
  * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
3
  * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
- *
5
- * removed:
6
- * - dependencies:
7
- * - tslib
8
- * - files
9
- * - compose.ts
10
- * - methods:
11
- * - usePipeline
12
- * - assertContainer
13
- * - assertContext
14
- * - isContext
15
- * - isContainer
16
- * - pipeline.useLazy
17
- * - context.assert
18
4
  */
19
5
  export * from "./pipeline";
@@ -8,9 +8,9 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
8
8
  * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
9
9
  * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
10
10
  */
11
- import { createContext, createContainer, fromContainer, runHooks, useContainer, runWithContainer } from "./context";
11
+ import { createContext } from "./context";
12
12
  import { createCounter } from "./counter";
13
- export { createContext, createContainer, useContainer, runWithContainer };
13
+ export { createContext };
14
14
  export const isPipeline = input => Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
15
15
  const PipelineSymbol = Symbol.for('MODERN_PIPELINE');
16
16
 
@@ -24,9 +24,7 @@ const getMiddleware = input => {
24
24
  throw new Error(`${input} is not a Middleware`);
25
25
  };
26
26
 
27
- export const createPipeline = options => {
28
- const config = _objectSpread({}, options);
29
-
27
+ export const createPipeline = () => {
30
28
  const middlewares = [];
31
29
 
32
30
  const use = (...inputs) => {
@@ -34,50 +32,35 @@ export const createPipeline = options => {
34
32
  return pipeline;
35
33
  };
36
34
 
37
- const createCurrentCounter = (hooks, onLast, onLastWithContext) => {
35
+ const createCurrentCounter = onLast => {
38
36
  return createCounter((index, input, next) => {
39
37
  if (index >= middlewares.length) {
40
38
  if (onLast) {
41
- if (onLastWithContext) {
42
- return runHooks(() => onLast(input), hooks);
43
- }
44
-
45
39
  return onLast(input);
46
40
  }
47
41
 
48
42
  throw new Error(`Expect returning a value, but all middlewares just calling next()`);
49
43
  }
50
44
 
51
- return runHooks(() => middlewares[index](input, next), hooks);
45
+ return middlewares[index](input, next);
52
46
  });
53
47
  };
54
48
 
55
- const currentContainer = createContainer(config.contexts);
56
- const currentHooks = fromContainer(currentContainer);
57
- const currentCounter = createCurrentCounter(currentHooks);
49
+ const currentCounter = createCurrentCounter();
58
50
 
59
51
  const getCounter = options => {
60
52
  if (!options) {
61
53
  return currentCounter;
62
54
  }
63
55
 
64
- if (options !== null && options !== void 0 && options.container) {
65
- const hooks = fromContainer(options === null || options === void 0 ? void 0 : options.container);
66
- return options !== null && options !== void 0 && options.onLast ? createCurrentCounter(hooks, options.onLast, typeof options.onLastWithContext === 'boolean' ? options.onLastWithContext : true) : createCurrentCounter(hooks);
67
- }
68
-
69
- return options !== null && options !== void 0 && options.onLast ? createCurrentCounter(currentHooks, options.onLast, typeof options.onLastWithContext === 'boolean' ? options.onLastWithContext : true) : createCurrentCounter(currentHooks);
56
+ return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
70
57
  };
71
58
 
72
59
  const run = (input, options) => getCounter(options).start(input);
73
60
 
74
- const middleware = (input, next) => {
75
- const container = useContainer();
76
- return run(input, {
77
- container,
78
- onLast: next
79
- });
80
- };
61
+ const middleware = (input, next) => run(input, {
62
+ onLast: next
63
+ });
81
64
 
82
65
  const pipeline = {
83
66
  [PipelineSymbol]: true,
@@ -87,7 +70,7 @@ export const createPipeline = options => {
87
70
  };
88
71
  return pipeline;
89
72
  };
90
- export const createAsyncPipeline = options => {
91
- const pipeline = createPipeline(options);
73
+ export const createAsyncPipeline = () => {
74
+ const pipeline = createPipeline();
92
75
  return _objectSpread({}, pipeline);
93
76
  };
@@ -4,16 +4,17 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import { runWithContainer, createContainer } from "../farrow-pipeline";
8
7
  import { generateRunner, DEFAULT_OPTIONS } from "./sync";
9
- import { useRunner } from "./runner";
10
8
  import { checkPlugins, isObject, hasOwnProperty, sortPlugins, includePlugin } from "./shared";
11
9
  const ASYNC_PLUGIN_SYMBOL = 'ASYNC_PLUGIN_SYMBOL';
12
10
  export const createAsyncManager = (hooks, api) => {
13
11
  let index = 0;
12
+ let runners;
14
13
 
15
14
  let currentHooks = _objectSpread({}, hooks);
16
15
 
16
+ const useRunner = () => runners;
17
+
17
18
  const registerHook = extraHooks => {
18
19
  currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
19
20
  };
@@ -80,23 +81,18 @@ export const createAsyncManager = (hooks, api) => {
80
81
  plugins = [];
81
82
  };
82
83
 
83
- const currentContainer = createContainer();
84
-
85
- const init = async options => {
86
- const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
84
+ const init = async () => {
87
85
  const sortedPlugins = sortPlugins(plugins);
88
86
 
89
87
  const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
90
88
 
91
89
  checkPlugins(sortedPlugins);
92
- const hooksList = await Promise.all(sortedPlugins.map(plugin => runWithContainer(() => plugin.setup(mergedPluginAPI), container)));
93
- return generateRunner(hooksList, container, currentHooks);
90
+ const hooksList = await Promise.all(sortedPlugins.map(plugin => plugin.setup(mergedPluginAPI)));
91
+ runners = generateRunner(hooksList, currentHooks);
92
+ return runners;
94
93
  };
95
94
 
96
- const run = (cb, options) => {
97
- const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
98
- return runWithContainer(cb, container);
99
- };
95
+ const run = cb => cb();
100
96
 
101
97
  const manager = {
102
98
  createPlugin,
@@ -1,4 +1,3 @@
1
1
  export * from "./sync";
2
2
  export * from "./async";
3
- export * from "./runner";
4
3
  export * from "./types";
@@ -4,10 +4,9 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import { isPipeline, createPipeline, runWithContainer, createContainer } from "../farrow-pipeline";
7
+ import { isPipeline, createPipeline } from "../farrow-pipeline";
8
8
  import { isWaterfall, createWaterfall, isAsyncWaterfall, createAsyncWaterfall } from "../waterfall";
9
9
  import { isWorkflow, createWorkflow, isAsyncWorkflow, createAsyncWorkflow, isParallelWorkflow, createParallelWorkflow } from "../workflow";
10
- import { RunnerContext, useRunner } from "./runner";
11
10
  import { checkPlugins, hasOwnProperty, includePlugin, isObject, sortPlugins } from "./shared";
12
11
  const SYNC_PLUGIN_SYMBOL = 'SYNC_PLUGIN_SYMBOL';
13
12
  export const DEFAULT_OPTIONS = {
@@ -21,9 +20,12 @@ export const DEFAULT_OPTIONS = {
21
20
  };
22
21
  export const createManager = (hooks, api) => {
23
22
  let index = 0;
23
+ let runners;
24
24
 
25
25
  let currentHooks = _objectSpread({}, hooks);
26
26
 
27
+ const useRunner = () => runners;
28
+
27
29
  const registerHook = extraHooks => {
28
30
  currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
29
31
  };
@@ -89,23 +91,18 @@ export const createManager = (hooks, api) => {
89
91
  plugins = [];
90
92
  };
91
93
 
92
- const currentContainer = createContainer();
93
-
94
- const init = options => {
95
- const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
94
+ const init = () => {
96
95
  const sortedPlugins = sortPlugins(plugins);
97
96
 
98
97
  const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
99
98
 
100
99
  checkPlugins(sortedPlugins);
101
- const hooksList = sortedPlugins.map(plugin => runWithContainer(() => plugin.setup(mergedPluginAPI), container));
102
- return generateRunner(hooksList, container, currentHooks);
100
+ const hooksList = sortedPlugins.map(plugin => plugin.setup(mergedPluginAPI));
101
+ runners = generateRunner(hooksList, currentHooks);
102
+ return runners;
103
103
  };
104
104
 
105
- const run = (cb, options) => {
106
- const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
107
- return runWithContainer(cb, container);
108
- };
105
+ const run = cb => cb();
109
106
 
110
107
  const manager = {
111
108
  createPlugin,
@@ -123,9 +120,9 @@ export const createManager = (hooks, api) => {
123
120
 
124
121
  return clone();
125
122
  };
126
- export const generateRunner = (hooksList, container, hooksMap) => {
123
+ export const generateRunner = (hooksList, hooksMap) => {
127
124
  const runner = {};
128
- const cloneShape = closeHooksMap(hooksMap);
125
+ const cloneShape = cloneHooksMap(hooksMap);
129
126
 
130
127
  if (hooksMap) {
131
128
  for (const key in cloneShape) {
@@ -141,13 +138,10 @@ export const generateRunner = (hooksList, container, hooksMap) => {
141
138
  // @ts-expect-error
142
139
 
143
140
 
144
- runner[key] = (input, options) => cloneShape[key].run(input, _objectSpread({
145
- container
146
- }, options));
141
+ runner[key] = (input, options) => cloneShape[key].run(input, _objectSpread({}, options));
147
142
  }
148
143
  }
149
144
 
150
- container.write(RunnerContext, runner);
151
145
  return runner;
152
146
  };
153
147
  export const cloneHook = hook => {
@@ -177,7 +171,7 @@ export const cloneHook = hook => {
177
171
 
178
172
  throw new Error(`Unknown hook: ${hook}`);
179
173
  };
180
- export const closeHooksMap = record => {
174
+ export const cloneHooksMap = record => {
181
175
  if (!record) {
182
176
  return record;
183
177
  }
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import { createAsyncPipeline, useContainer } from "../farrow-pipeline";
7
+ import { createAsyncPipeline } from "../farrow-pipeline";
8
8
  const ASYNC_WATERFALL_SYMBOL = Symbol.for('MODERN_ASYNC_WATERFALL');
9
9
  export const getAsyncBrook = input => {
10
10
  if (typeof input === 'function') {
@@ -28,9 +28,7 @@ export const createAsyncWaterfall = () => {
28
28
  }));
29
29
 
30
30
  const middleware = input => {
31
- const container = useContainer();
32
31
  return pipeline.run(input, {
33
- container,
34
32
  onLast: input => input
35
33
  });
36
34
  };
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import { useContainer, createPipeline } from "../farrow-pipeline";
7
+ import { createPipeline } from "../farrow-pipeline";
8
8
  const WATERFALL_SYMBOL = Symbol.for('MODERN_WATERFALL');
9
9
  export const getBrook = input => {
10
10
  if (typeof input === 'function') {
@@ -28,9 +28,7 @@ export const createWaterfall = () => {
28
28
  }));
29
29
 
30
30
  const middleware = input => {
31
- const container = useContainer();
32
31
  return pipeline.run(input, {
33
- container,
34
32
  onLast: input => input
35
33
  });
36
34
  };
@@ -15,10 +15,10 @@ export const createAsyncWorkflow = () => {
15
15
  return workflow;
16
16
  };
17
17
 
18
- const run = async (input, options) => {
19
- const result = pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
18
+ const run = async input => {
19
+ const result = pipeline.run(input, {
20
20
  onLast: () => []
21
- }));
21
+ });
22
22
 
23
23
  if (isPromise(result)) {
24
24
  return result.then(result => result.filter(Boolean));
@@ -15,9 +15,9 @@ export const createParallelWorkflow = () => {
15
15
  return workflow;
16
16
  };
17
17
 
18
- const run = async (input, options) => Promise.all(pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
18
+ const run = async input => Promise.all(pipeline.run(input, {
19
19
  onLast: () => []
20
- }))).then(result => result.filter(Boolean));
20
+ })).then(result => result.filter(Boolean));
21
21
 
22
22
  const workflow = _objectSpread(_objectSpread({}, pipeline), {}, {
23
23
  run,
@@ -14,10 +14,10 @@ export const createWorkflow = () => {
14
14
  return workflow;
15
15
  };
16
16
 
17
- const run = (input, options) => {
18
- const result = pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
17
+ const run = input => {
18
+ const result = pipeline.run(input, {
19
19
  onLast: () => []
20
- }));
20
+ });
21
21
  return result.filter(Boolean);
22
22
  };
23
23
 
@@ -3,47 +3,36 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useContainer = exports.runWithContainer = exports.runHooks = exports.fromContainer = exports.createContext = exports.createContainer = void 0;
7
-
8
- var _hook = require("./hook");
6
+ exports.createContext = void 0;
9
7
 
10
8
  /**
11
9
  * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
12
10
  * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
13
11
  */
14
- const ContextSymbol = Symbol.for('MODERN_CONTEXT');
15
-
16
12
  const createContext = value => {
17
- const id = Symbol('MODERN_CONTEXT_ID');
13
+ let currentValue;
18
14
 
19
15
  const create = value => {
20
- const use = () => {
21
- const container = useContainer();
22
- return Object.seal({
23
- get value() {
24
- return container.read(Context);
25
- },
16
+ currentValue = value;
26
17
 
27
- set value(v) {
28
- container.write(Context, v);
29
- }
18
+ const use = () => ({
19
+ get value() {
20
+ return currentValue;
21
+ },
30
22
 
31
- });
32
- };
23
+ set value(v) {
24
+ currentValue = v;
25
+ }
33
26
 
34
- const get = () => {
35
- const container = useContainer();
36
- return container.read(Context);
37
- };
27
+ });
28
+
29
+ const get = () => currentValue;
38
30
 
39
31
  const set = v => {
40
- const container = useContainer();
41
- container.write(Context, v);
32
+ currentValue = v;
42
33
  };
43
34
 
44
35
  const Context = {
45
- id,
46
- [ContextSymbol]: value,
47
36
  create,
48
37
  use,
49
38
  get,
@@ -55,66 +44,4 @@ const createContext = value => {
55
44
  return create(value);
56
45
  };
57
46
 
58
- exports.createContext = createContext;
59
-
60
- const createContextMap = storage => {
61
- const contextMap = new Map();
62
- const contexts = Object.values(storage); // eslint-disable-next-line @typescript-eslint/prefer-for-of
63
-
64
- for (let i = 0; i < contexts.length; i++) {
65
- contextMap.set(contexts[i].id, contexts[i]);
66
- }
67
-
68
- return contextMap;
69
- };
70
-
71
- const createContainer = (ContextStorage = {}) => {
72
- const contextMap = createContextMap(ContextStorage);
73
-
74
- const read = context => {
75
- const target = contextMap.get(context.id);
76
-
77
- if (target) {
78
- return target[ContextSymbol];
79
- }
80
-
81
- return context[ContextSymbol];
82
- };
83
-
84
- const write = (context, value) => {
85
- contextMap.set(context.id, context.create(value));
86
- };
87
-
88
- return Object.freeze({
89
- read,
90
- write
91
- });
92
- };
93
-
94
- exports.createContainer = createContainer;
95
- const {
96
- run,
97
- hooks
98
- } = (0, _hook.createHooks)({
99
- useContainer: () => {
100
- throw new Error(`Can't call useContainer out of scope, it should be placed on top of the function`);
101
- }
102
- });
103
- const runHooks = run;
104
- exports.runHooks = runHooks;
105
- const {
106
- useContainer
107
- } = hooks;
108
- exports.useContainer = useContainer;
109
-
110
- const fromContainer = container => ({
111
- useContainer: () => {
112
- return container;
113
- }
114
- });
115
-
116
- exports.fromContainer = fromContainer;
117
-
118
- const runWithContainer = (f, container) => runHooks(f, fromContainer(container));
119
-
120
- exports.runWithContainer = runWithContainer;
47
+ exports.createContext = createContext;