piral-containers 1.6.0-beta.7240 → 1.6.0-beta.7243

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/lib/actions.js CHANGED
@@ -1,33 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.replaceState = exports.destroyState = exports.createState = void 0;
4
- const piral_core_1 = require("piral-core");
5
- function createState(ctx, id, data) {
1
+ import { withKey, withoutKey } from 'piral-core';
2
+ export function createState(ctx, id, data) {
6
3
  ctx.dispatch((state) => ({
7
4
  ...state,
8
- containers: (0, piral_core_1.withKey)(state.containers, id, data),
5
+ containers: withKey(state.containers, id, data),
9
6
  }));
10
7
  }
11
- exports.createState = createState;
12
- function destroyState(ctx, id) {
8
+ export function destroyState(ctx, id) {
13
9
  ctx.dispatch((state) => ({
14
10
  ...state,
15
- containers: (0, piral_core_1.withoutKey)(state.containers, id),
11
+ containers: withoutKey(state.containers, id),
16
12
  }));
17
13
  }
18
- exports.destroyState = destroyState;
19
- function replaceState(ctx, id, dispatch) {
14
+ export function replaceState(ctx, id, dispatch) {
20
15
  ctx.dispatch((state) => {
21
16
  const oldState = state.containers[id];
22
17
  const newState = dispatch(oldState);
23
18
  return {
24
19
  ...state,
25
- containers: (0, piral_core_1.withKey)(state.containers, id, {
20
+ containers: withKey(state.containers, id, {
26
21
  ...oldState,
27
22
  ...newState,
28
23
  }),
29
24
  };
30
25
  });
31
26
  }
32
- exports.replaceState = replaceState;
33
27
  //# sourceMappingURL=actions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":";;;AAAA,2CAAsF;AAEtF,SAAgB,WAAW,CAAS,GAAuB,EAAE,EAAU,EAAE,IAAY;IACnF,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACvB,GAAG,KAAK;QACR,UAAU,EAAE,IAAA,oBAAO,E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AU;IAC9D,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACvB,GAAG,KAAK;QACR,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,CAAC;KAC7C,CAAC,CAAC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,YAAY,CAAS,GAAuB,EAAE,EAAU,EAAE,QAAiC;IACzG,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;QACrB,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACtC,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACpC,OAAO;YACL,GAAG,KAAK;YACR,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,EAAE;gBACxC,GAAG,QAAQ;gBACX,GAAG,QAAQ;aACZ,CAAC;SACH,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
package/lib/create.js CHANGED
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createContainersApi = void 0;
4
- const actions = require("./actions");
5
- const piral_core_1 = require("piral-core");
6
- const withPiletState_1 = require("./withPiletState");
1
+ import * as actions from './actions';
2
+ import { buildName } from 'piral-core';
3
+ import { withPiletState } from './withPiletState';
7
4
  /**
8
5
  * Creates new Pilet API extensions for supporting pilet global state containers.
9
6
  */
10
- function createContainersApi(config = {}) {
7
+ export function createContainersApi(config = {}) {
11
8
  return (context) => {
12
9
  context.defineActions(actions);
13
10
  context.dispatch((state) => ({
@@ -22,18 +19,17 @@ function createContainersApi(config = {}) {
22
19
  throw new Error('Missing options. "state" and "actions" are required.');
23
20
  }
24
21
  const actions = {};
25
- const id = (0, piral_core_1.buildName)(target.name, containers++);
22
+ const id = buildName(target.name, containers++);
26
23
  const cb = (dispatch) => context.replaceState(id, dispatch);
27
24
  context.createState(id, options.state);
28
25
  Object.keys(options.actions).forEach((key) => {
29
26
  const action = options.actions[key];
30
27
  actions[key] = (...args) => action.call(api, cb, ...args);
31
28
  });
32
- return (component) => (0, withPiletState_1.withPiletState)(component, id, actions);
29
+ return (component) => withPiletState(component, id, actions);
33
30
  },
34
31
  };
35
32
  };
36
33
  };
37
34
  }
38
- exports.createContainersApi = createContainersApi;
39
35
  //# sourceMappingURL=create.js.map
package/lib/create.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;AACrC,2CAAqE;AACrE,qDAAkD;AAQlD;;GAEG;AACH,SAAgB,mBAAmB,CAAC,SAA2B,EAAE;IAC/D,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAE/B,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAC3B,GAAG,KAAK;YACR,UAAU,EAAE,EAAE;SACf,CAAC,CAAC,CAAC;QAEJ,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;YACrB,IAAI,UAAU,GAAG,CAAC,CAAC;YAEnB,OAAO;gBACL,WAAW,CAAC,OAAO;oBACjB,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,EAAE;wBACxF,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;qBACzE;oBAED,MAAM,OAAO,GAAG,EAAE,CAAC;oBACnB,MAAM,EAAE,GAAG,IAAA,sBAAS,EAAC,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;oBAChD,MAAM,EAAE,GAAG,CAAC,QAA8B,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;oBAClF,OAAO,CAAC,WAA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,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,EAAE;wBACxF,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;qBACzE;oBAED,MAAM,OAAO,GAAG,EAAE,CAAC;oBACnB,MAAM,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;oBAChD,MAAM,EAAE,GAAG,CAAC,QAA8B,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;oBAClF,OAAO,CAAC,WAAW,CAAC,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;oBAEvC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;wBAC3C,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;wBACpC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;oBAC5D,CAAC,CAAC,CAAC;oBAEH,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,cAAc,CAAC,SAAS,EAAE,EAAE,EAAE,OAAO,CAAQ,CAAC;gBACtE,CAAC;aACF,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
package/lib/index.js CHANGED
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./create"), exports);
5
- tslib_1.__exportStar(require("./types"), exports);
1
+ export * from './create';
2
+ export * from './types';
6
3
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAAyB;AACzB,kDAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
package/lib/types.js CHANGED
@@ -1,3 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
3
2
  //# sourceMappingURL=types.js.map
@@ -1,15 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withPiletState = void 0;
4
- const React = require("react");
5
- const piral_core_1 = require("piral-core");
6
- function withPiletState(Component, id, actions) {
1
+ import * as React from 'react';
2
+ import { useGlobalState } from 'piral-core';
3
+ export function withPiletState(Component, id, actions) {
7
4
  const StateView = (props) => {
8
- const state = (0, piral_core_1.useGlobalState)((s) => s.containers[id]);
5
+ const state = useGlobalState((s) => s.containers[id]);
9
6
  return React.createElement(Component, { state: state, actions: actions, ...props });
10
7
  };
11
8
  StateView.displayName = `StateView_${id}`;
12
9
  return StateView;
13
10
  }
14
- exports.withPiletState = withPiletState;
15
11
  //# sourceMappingURL=withPiletState.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"withPiletState.js","sourceRoot":"","sources":["../src/withPiletState.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAA4C;AAG5C,SAAgB,cAAc,CAC5B,SAA6E,EAC7E,EAAU,EACV,OAAgB;IAEhB,MAAM,SAAS,GAAqB,CAAC,KAAK,EAAE,EAAE;QAC5C,MAAM,KAAK,GAAG,IAAA,2BAAc,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;QACtD,OAAO,oBAAC,SAAS,IAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,KAAM,KAAK,GAAI,CAAC;IAClE,CAAC,CAAC;IACF,SAAS,CAAC,WAAW,GAAG,aAAa,EAAE,EAAE,CAAC;IAE1C,OAAO,SAAS,CAAC;AACnB,CAAC;AAZD,wCAYC"}
1
+ {"version":3,"file":"withPiletState.js","sourceRoot":"","sources":["../src/withPiletState.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C,MAAM,UAAU,cAAc,CAC5B,SAA6E,EAC7E,EAAU,EACV,OAAgB;IAEhB,MAAM,SAAS,GAAqB,CAAC,KAAK,EAAE,EAAE;QAC5C,MAAM,KAAK,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;QACtD,OAAO,oBAAC,SAAS,IAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,KAAM,KAAK,GAAI,CAAC;IAClE,CAAC,CAAC;IACF,SAAS,CAAC,WAAW,GAAG,aAAa,EAAE,EAAE,CAAC;IAE1C,OAAO,SAAS,CAAC;AACnB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-containers",
3
- "version": "1.6.0-beta.7240",
3
+ "version": "1.6.0-beta.7243",
4
4
  "description": "Plugin for creating a pilet state container in Piral.",
5
5
  "keywords": [
6
6
  "piral",
@@ -17,29 +17,16 @@
17
17
  "author": "smapiot",
18
18
  "homepage": "https://piral.io",
19
19
  "license": "MIT",
20
- "module": "esm/index.js",
20
+ "module": "lib/index.js",
21
21
  "main": "lib/index.js",
22
22
  "typings": "lib/index.d.ts",
23
23
  "exports": {
24
- ".": {
25
- "import": "./esm/index.js",
26
- "require": "./lib/index.js"
27
- },
28
- "./esm/*": {
29
- "import": "./esm/*"
30
- },
31
- "./lib/*": {
32
- "require": "./lib/*"
33
- },
34
- "./_/*": {
35
- "import": "./esm/*.js",
36
- "require": "./lib/*.js"
37
- },
24
+ ".": "./lib/index.js",
25
+ "./lib/*": "./lib/*",
38
26
  "./package.json": "./package.json"
39
27
  },
40
28
  "sideEffects": false,
41
29
  "files": [
42
- "esm",
43
30
  "lib",
44
31
  "src",
45
32
  "piral-containers.min.js"
@@ -53,17 +40,16 @@
53
40
  },
54
41
  "scripts": {
55
42
  "cleanup": "rimraf esm lib piral-containers.min.js",
56
- "build": "yarn build:bundle && yarn build:commonjs && yarn build:esnext",
43
+ "build": "yarn build:bundle && yarn build:esnext",
57
44
  "build:bundle": "esbuild src/index.ts --outfile=piral-containers.min.js --bundle --external:piral-core --external:react --minify --global-name=piralContainers",
58
- "build:commonjs": "tsc --project tsconfig.json --outDir lib --module commonjs",
59
- "build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
45
+ "build:esnext": "tsc --project tsconfig.json --outDir lib --module esnext",
60
46
  "typedoc": "typedoc --json ../../../docs/types/piral-containers.json src --exclude \"src/**/*.test.*\"",
61
47
  "test": "echo \"Error: run tests from root\" && exit 1"
62
48
  },
63
49
  "devDependencies": {
64
50
  "@types/react": "^18.0.0",
65
- "piral-core": "1.6.0-beta.7240",
51
+ "piral-core": "1.6.0-beta.7243",
66
52
  "react": "^18.0.0"
67
53
  },
68
- "gitHead": "2fd8ff47d9a7e0666e4e6bc1dc5a7ef45e8e9f39"
54
+ "gitHead": "bbb6e4f78c61b6ef753099a5b378ad2708565ce3"
69
55
  }
package/esm/actions.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { StateDispatcher, GlobalStateContext } from 'piral-core';
2
- export declare function createState<TState>(ctx: GlobalStateContext, id: string, data: TState): void;
3
- export declare function destroyState(ctx: GlobalStateContext, id: string): void;
4
- export declare function replaceState<TState>(ctx: GlobalStateContext, id: string, dispatch: StateDispatcher<TState>): void;
package/esm/actions.js DELETED
@@ -1,27 +0,0 @@
1
- import { withKey, withoutKey } from 'piral-core';
2
- export function createState(ctx, id, data) {
3
- ctx.dispatch((state) => ({
4
- ...state,
5
- containers: withKey(state.containers, id, data),
6
- }));
7
- }
8
- export function destroyState(ctx, id) {
9
- ctx.dispatch((state) => ({
10
- ...state,
11
- containers: withoutKey(state.containers, id),
12
- }));
13
- }
14
- export function replaceState(ctx, id, dispatch) {
15
- ctx.dispatch((state) => {
16
- const oldState = state.containers[id];
17
- const newState = dispatch(oldState);
18
- return {
19
- ...state,
20
- containers: withKey(state.containers, id, {
21
- ...oldState,
22
- ...newState,
23
- }),
24
- };
25
- });
26
- }
27
- //# sourceMappingURL=actions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,OAAO,EAAE,UAAU,EAAsB,MAAM,YAAY,CAAC;AAEtF,MAAM,UAAU,WAAW,CAAS,GAAuB,EAAE,EAAU,EAAE,IAAY;IACnF,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACvB,GAAG,KAAK;QACR,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,EAAE,IAAI,CAAC;KAChD,CAAC,CAAC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,GAAuB,EAAE,EAAU;IAC9D,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACvB,GAAG,KAAK;QACR,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,CAAC;KAC7C,CAAC,CAAC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,YAAY,CAAS,GAAuB,EAAE,EAAU,EAAE,QAAiC;IACzG,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;QACrB,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACtC,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACpC,OAAO;YACL,GAAG,KAAK;YACR,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,EAAE;gBACxC,GAAG,QAAQ;gBACX,GAAG,QAAQ;aACZ,CAAC;SACH,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
package/esm/create.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { PiralPlugin } from 'piral-core';
2
- import { PiletContainersApi } from './types';
3
- /**
4
- * Available configuration options for the container plugin.
5
- */
6
- export interface ContainersConfig {
7
- }
8
- /**
9
- * Creates new Pilet API extensions for supporting pilet global state containers.
10
- */
11
- export declare function createContainersApi(config?: ContainersConfig): PiralPlugin<PiletContainersApi>;
package/esm/create.js DELETED
@@ -1,35 +0,0 @@
1
- import * as actions from './actions';
2
- import { buildName } from 'piral-core';
3
- import { withPiletState } from './withPiletState';
4
- /**
5
- * Creates new Pilet API extensions for supporting pilet global state containers.
6
- */
7
- export function createContainersApi(config = {}) {
8
- return (context) => {
9
- context.defineActions(actions);
10
- context.dispatch((state) => ({
11
- ...state,
12
- containers: {},
13
- }));
14
- return (api, target) => {
15
- let containers = 0;
16
- return {
17
- createState(options) {
18
- if (!options || typeof options.actions !== 'object' || typeof options.state !== 'object') {
19
- throw new Error('Missing options. "state" and "actions" are required.');
20
- }
21
- const actions = {};
22
- const id = buildName(target.name, containers++);
23
- const cb = (dispatch) => context.replaceState(id, dispatch);
24
- context.createState(id, options.state);
25
- Object.keys(options.actions).forEach((key) => {
26
- const action = options.actions[key];
27
- actions[key] = (...args) => action.call(api, cb, ...args);
28
- });
29
- return (component) => withPiletState(component, id, actions);
30
- },
31
- };
32
- };
33
- };
34
- }
35
- //# sourceMappingURL=create.js.map
package/esm/create.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,SAAS,EAAgC,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,cAAc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,CAAC,CAAC,CAAC;oBAEH,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,cAAc,CAAC,SAAS,EAAE,EAAE,EAAE,OAAO,CAAQ,CAAC;gBACtE,CAAC;aACF,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
package/esm/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './create';
2
- export * from './types';
package/esm/index.js DELETED
@@ -1,3 +0,0 @@
1
- export * from './create';
2
- export * from './types';
3
- //# sourceMappingURL=index.js.map
package/esm/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
package/esm/types.d.ts DELETED
@@ -1,74 +0,0 @@
1
- import type { ComponentType, FC } from 'react';
2
- import type { RemainingArgs, StateDispatcher } from 'piral-core';
3
- declare module 'piral-core/lib/types/custom' {
4
- interface PiletCustomApi extends PiletContainersApi {
5
- }
6
- interface PiralCustomState {
7
- /**
8
- * The relevant state for the registered containers.
9
- */
10
- containers: Record<string, any>;
11
- }
12
- interface PiralCustomActions {
13
- /**
14
- * Creates a new local state.
15
- * @param id The id of the state.
16
- * @param state The initial state to use.
17
- */
18
- createState<TState>(id: string, state: TState): void;
19
- /**
20
- * Destroys an existing local state.
21
- * @param id The id of the state.
22
- */
23
- destroyState(id: string): void;
24
- /**
25
- * Replaces the local state with the provided state.
26
- * @param id The id of the local state.
27
- * @param state The new state to use.
28
- */
29
- replaceState<TState>(id: string, reducer: StateDispatcher<TState>): void;
30
- }
31
- }
32
- export interface PiletContainersApi {
33
- /**
34
- * Creates a state container for persisting some global state.
35
- * @param options The options for creating the state container.
36
- */
37
- createState<TState, TActions extends StateContainerReducers<TState>>(options: StateContainerOptions<TState, TActions>): StateContainer<TState, StateContainerActions<TActions>>;
38
- }
39
- export interface StateContainerReducer<TState> {
40
- (dispatch: StateDispatcher<TState>): void;
41
- }
42
- export type StateContainerReducers<TState> = {
43
- [name: string]: (dispatch: StateContainerReducer<TState>, ...args: any) => void;
44
- };
45
- export interface StateContainerOptions<TState, TActions extends StateContainerReducers<TState>> {
46
- /**
47
- * The initial state value.
48
- */
49
- state: TState;
50
- /**
51
- * The available actions.
52
- */
53
- actions: TActions;
54
- }
55
- export interface StateConnectorProps<TState, TAction> {
56
- /**
57
- * The currently available state.
58
- */
59
- state: TState;
60
- /**
61
- * The actions for changing the state.
62
- */
63
- actions: TAction;
64
- }
65
- export type StateContainerActions<TActions> = {
66
- [P in keyof TActions]: (...args: RemainingArgs<TActions[P]>) => void;
67
- };
68
- export interface StateContainer<TState, TActions> {
69
- /**
70
- * State container connector function for wrapping a component.
71
- * @param component The component to connect by providing a state and an action prop.
72
- */
73
- <TProps>(component: ComponentType<TProps & StateConnectorProps<TState, TActions>>): FC<TProps>;
74
- }
package/esm/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
package/esm/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- import * as React from 'react';
2
- import { StateConnectorProps } from './types';
3
- export declare function withPiletState<TState, TAction, TProps>(Component: React.ComponentType<TProps & StateConnectorProps<TState, TAction>>, id: string, actions: TAction): React.FC<TProps>;
@@ -1,11 +0,0 @@
1
- import * as React from 'react';
2
- import { useGlobalState } from 'piral-core';
3
- export function withPiletState(Component, id, actions) {
4
- const StateView = (props) => {
5
- const state = useGlobalState((s) => s.containers[id]);
6
- return React.createElement(Component, { state: state, actions: actions, ...props });
7
- };
8
- StateView.displayName = `StateView_${id}`;
9
- return StateView;
10
- }
11
- //# sourceMappingURL=withPiletState.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"withPiletState.js","sourceRoot":"","sources":["../src/withPiletState.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C,MAAM,UAAU,cAAc,CAC5B,SAA6E,EAC7E,EAAU,EACV,OAAgB;IAEhB,MAAM,SAAS,GAAqB,CAAC,KAAK,EAAE,EAAE;QAC5C,MAAM,KAAK,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;QACtD,OAAO,oBAAC,SAAS,IAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,KAAM,KAAK,GAAI,CAAC;IAClE,CAAC,CAAC;IACF,SAAS,CAAC,WAAW,GAAG,aAAa,EAAE,EAAE,CAAC;IAE1C,OAAO,SAAS,CAAC;AACnB,CAAC"}