piral-containers
Advanced tools
Comparing version 1.6.0-beta.7240 to 1.6.0-beta.7243
@@ -1,20 +0,15 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.replaceState = exports.destroyState = exports.createState = void 0; | ||
const piral_core_1 = require("piral-core"); | ||
function createState(ctx, id, data) { | ||
import { withKey, withoutKey } from 'piral-core'; | ||
export function createState(ctx, id, data) { | ||
ctx.dispatch((state) => ({ | ||
...state, | ||
containers: (0, piral_core_1.withKey)(state.containers, id, data), | ||
containers: withKey(state.containers, id, data), | ||
})); | ||
} | ||
exports.createState = createState; | ||
function destroyState(ctx, id) { | ||
export function destroyState(ctx, id) { | ||
ctx.dispatch((state) => ({ | ||
...state, | ||
containers: (0, piral_core_1.withoutKey)(state.containers, id), | ||
containers: withoutKey(state.containers, id), | ||
})); | ||
} | ||
exports.destroyState = destroyState; | ||
function replaceState(ctx, id, dispatch) { | ||
export function replaceState(ctx, id, dispatch) { | ||
ctx.dispatch((state) => { | ||
@@ -25,3 +20,3 @@ const oldState = state.containers[id]; | ||
...state, | ||
containers: (0, piral_core_1.withKey)(state.containers, id, { | ||
containers: withKey(state.containers, id, { | ||
...oldState, | ||
@@ -33,3 +28,2 @@ ...newState, | ||
} | ||
exports.replaceState = replaceState; | ||
//# sourceMappingURL=actions.js.map |
@@ -1,11 +0,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createContainersApi = void 0; | ||
const actions = require("./actions"); | ||
const piral_core_1 = require("piral-core"); | ||
const withPiletState_1 = require("./withPiletState"); | ||
import * as actions from './actions'; | ||
import { buildName } from 'piral-core'; | ||
import { withPiletState } from './withPiletState'; | ||
/** | ||
* Creates new Pilet API extensions for supporting pilet global state containers. | ||
*/ | ||
function createContainersApi(config = {}) { | ||
export function createContainersApi(config = {}) { | ||
return (context) => { | ||
@@ -25,3 +22,3 @@ context.defineActions(actions); | ||
const actions = {}; | ||
const id = (0, piral_core_1.buildName)(target.name, containers++); | ||
const id = buildName(target.name, containers++); | ||
const cb = (dispatch) => context.replaceState(id, dispatch); | ||
@@ -33,3 +30,3 @@ context.createState(id, options.state); | ||
}); | ||
return (component) => (0, withPiletState_1.withPiletState)(component, id, actions); | ||
return (component) => withPiletState(component, id, actions); | ||
}, | ||
@@ -40,3 +37,2 @@ }; | ||
} | ||
exports.createContainersApi = createContainersApi; | ||
//# sourceMappingURL=create.js.map |
@@ -1,6 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./create"), exports); | ||
tslib_1.__exportStar(require("./types"), exports); | ||
export * from './create'; | ||
export * from './types'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=types.js.map |
@@ -1,9 +0,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.withPiletState = void 0; | ||
const React = require("react"); | ||
const piral_core_1 = require("piral-core"); | ||
function withPiletState(Component, id, actions) { | ||
import * as React from 'react'; | ||
import { useGlobalState } from 'piral-core'; | ||
export function withPiletState(Component, id, actions) { | ||
const StateView = (props) => { | ||
const state = (0, piral_core_1.useGlobalState)((s) => s.containers[id]); | ||
const state = useGlobalState((s) => s.containers[id]); | ||
return React.createElement(Component, { state: state, actions: actions, ...props }); | ||
@@ -14,3 +11,2 @@ }; | ||
} | ||
exports.withPiletState = withPiletState; | ||
//# sourceMappingURL=withPiletState.js.map |
{ | ||
"name": "piral-containers", | ||
"version": "1.6.0-beta.7240", | ||
"version": "1.6.0-beta.7243", | ||
"description": "Plugin for creating a pilet state container in Piral.", | ||
@@ -20,20 +20,8 @@ "keywords": [ | ||
"license": "MIT", | ||
"module": "esm/index.js", | ||
"module": "lib/index.js", | ||
"main": "lib/index.js", | ||
"typings": "lib/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./esm/index.js", | ||
"require": "./lib/index.js" | ||
}, | ||
"./esm/*": { | ||
"import": "./esm/*" | ||
}, | ||
"./lib/*": { | ||
"require": "./lib/*" | ||
}, | ||
"./_/*": { | ||
"import": "./esm/*.js", | ||
"require": "./lib/*.js" | ||
}, | ||
".": "./lib/index.js", | ||
"./lib/*": "./lib/*", | ||
"./package.json": "./package.json" | ||
@@ -43,3 +31,2 @@ }, | ||
"files": [ | ||
"esm", | ||
"lib", | ||
@@ -58,6 +45,5 @@ "src", | ||
"cleanup": "rimraf esm lib piral-containers.min.js", | ||
"build": "yarn build:bundle && yarn build:commonjs && yarn build:esnext", | ||
"build": "yarn build:bundle && yarn build:esnext", | ||
"build:bundle": "esbuild src/index.ts --outfile=piral-containers.min.js --bundle --external:piral-core --external:react --minify --global-name=piralContainers", | ||
"build:commonjs": "tsc --project tsconfig.json --outDir lib --module commonjs", | ||
"build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext", | ||
"build:esnext": "tsc --project tsconfig.json --outDir lib --module esnext", | ||
"typedoc": "typedoc --json ../../../docs/types/piral-containers.json src --exclude \"src/**/*.test.*\"", | ||
@@ -68,6 +54,6 @@ "test": "echo \"Error: run tests from root\" && exit 1" | ||
"@types/react": "^18.0.0", | ||
"piral-core": "1.6.0-beta.7240", | ||
"piral-core": "1.6.0-beta.7243", | ||
"react": "^18.0.0" | ||
}, | ||
"gitHead": "2fd8ff47d9a7e0666e4e6bc1dc5a7ef45e8e9f39" | ||
"gitHead": "bbb6e4f78c61b6ef753099a5b378ad2708565ce3" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27335
26
484