piral-redux 0.13.7 → 0.14.0-alpha.3154
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/esm/create.js +29 -36
- package/esm/create.js.map +1 -1
- package/lib/create.js +32 -39
- package/lib/create.js.map +1 -1
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/src/create.ts +1 -3
package/esm/create.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
2
|
import { createElement } from 'react';
|
|
3
3
|
import { Provider, connect } from 'react-redux';
|
|
4
4
|
import { createStore } from 'redux';
|
|
@@ -8,34 +8,29 @@ function defaultReducer(state) {
|
|
|
8
8
|
/**
|
|
9
9
|
* Creates new Pilet API extensions for creating a Redux state container.
|
|
10
10
|
*/
|
|
11
|
-
export function createReduxApi(config) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var initialState = {
|
|
18
|
-
stores: {},
|
|
19
|
-
};
|
|
11
|
+
export function createReduxApi(config = {}) {
|
|
12
|
+
const { reducer = defaultReducer, enhancer } = config;
|
|
13
|
+
const otherReducers = {};
|
|
14
|
+
const initialState = { stores: {} };
|
|
15
|
+
const store = createStore(createReducer(), enhancer);
|
|
16
|
+
const provider = createElement(Provider, { store });
|
|
20
17
|
function createReducer() {
|
|
21
|
-
return
|
|
22
|
-
var _a, _b;
|
|
23
|
-
if (state === void 0) { state = initialState; }
|
|
18
|
+
return (state = initialState, action) => {
|
|
24
19
|
switch (action.type) {
|
|
25
20
|
case 'create-store': {
|
|
26
|
-
|
|
27
|
-
return
|
|
21
|
+
const stores = state.stores;
|
|
22
|
+
return Object.assign(Object.assign({}, state), { stores: Object.assign(Object.assign({}, stores), { [action.name]: action.value }) });
|
|
28
23
|
}
|
|
29
24
|
case 'destroy-store': {
|
|
30
|
-
|
|
31
|
-
return
|
|
25
|
+
const _a = state.stores, _b = action.name, _ = _a[_b], stores = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
26
|
+
return Object.assign(Object.assign({}, state), { stores: Object.assign({}, stores) });
|
|
32
27
|
}
|
|
33
28
|
case 'change-store': {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
const reducer = otherReducers[action.name];
|
|
30
|
+
const oldState = state.stores[action.name];
|
|
31
|
+
const newState = reducer(oldState, action.action);
|
|
37
32
|
if (oldState !== newState) {
|
|
38
|
-
return
|
|
33
|
+
return Object.assign(Object.assign({}, state), { stores: Object.assign(Object.assign({}, state.stores), { [action.name]: newState }) });
|
|
39
34
|
}
|
|
40
35
|
return state;
|
|
41
36
|
}
|
|
@@ -45,29 +40,27 @@ export function createReduxApi(config) {
|
|
|
45
40
|
}
|
|
46
41
|
};
|
|
47
42
|
}
|
|
48
|
-
return
|
|
43
|
+
return (context) => {
|
|
49
44
|
context.includeProvider(provider);
|
|
50
|
-
return
|
|
51
|
-
createReduxStore
|
|
52
|
-
|
|
45
|
+
return (_, meta) => ({
|
|
46
|
+
createReduxStore(reducer) {
|
|
47
|
+
const name = meta.name;
|
|
53
48
|
otherReducers[name] = reducer;
|
|
54
49
|
store.dispatch({
|
|
55
50
|
type: 'create-store',
|
|
56
|
-
name
|
|
51
|
+
name,
|
|
57
52
|
value: reducer(undefined, { type: '$init' }),
|
|
58
53
|
});
|
|
59
|
-
|
|
54
|
+
const dispatch = (action) => ({
|
|
60
55
|
type: 'change-store',
|
|
61
|
-
name
|
|
62
|
-
action
|
|
63
|
-
});
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
})(component);
|
|
68
|
-
};
|
|
56
|
+
name,
|
|
57
|
+
action,
|
|
58
|
+
});
|
|
59
|
+
return (component) => connect((state) => ({ state: state.stores[name] }), {
|
|
60
|
+
dispatch,
|
|
61
|
+
})(component);
|
|
69
62
|
},
|
|
70
|
-
});
|
|
63
|
+
});
|
|
71
64
|
};
|
|
72
65
|
}
|
|
73
66
|
//# sourceMappingURL=create.js.map
|
package/esm/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,WAAW,EAA0B,MAAM,OAAO,CAAC;AAyB5D,SAAS,cAAc,CAAI,KAAQ;IACjC,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,WAAW,EAA0B,MAAM,OAAO,CAAC;AAyB5D,SAAS,cAAc,CAAI,KAAQ;IACjC,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,SAAsB,EAAE;IACrD,MAAM,EAAE,OAAO,GAAG,cAAc,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IACtD,MAAM,aAAa,GAAG,EAAE,CAAC;IACzB,MAAM,YAAY,GAAoB,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IACrD,MAAM,KAAK,GAAG,WAAW,CAAC,aAAa,EAAkB,EAAE,QAAQ,CAAC,CAAC;IACrE,MAAM,QAAQ,GAAG,aAAa,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAEpD,SAAS,aAAa;QACpB,OAAO,CAAC,QAAyB,YAAY,EAAE,MAAuC,EAAmB,EAAE;YACzG,QAAQ,MAAM,CAAC,I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CAAC,GAAG,OAAO,CAAC;gBAC9B,KAAK,CAAC,QAAQ,CAAC;oBACb,IAAI,EAAE,cAAc;oBACpB,IAAI;oBACJ,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;iBAC7C,CAAC,CAAC;gBACH,MAAM,QAAQ,GAAG,CAAC,MAAW,EAAE,EAAE,CAAC,CAAC;oBACjC,IAAI,EAAE,cAAc;oBACpB,IAAI;oBACJ,MAAM;iBACP,CAAC,CAAC;gBACH,OAAO,CAAC,SAAS,EAAE,EAAE,CACnB,OAAO,CAAwD,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;oBACzG,QAAQ;iBACT,CAAC,CAAC,SAAS,CAAQ,CAAC;YACzB,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
package/lib/create.js
CHANGED
|
@@ -1,44 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createReduxApi = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const react_redux_1 = require("react-redux");
|
|
7
|
+
const redux_1 = require("redux");
|
|
8
8
|
function defaultReducer(state) {
|
|
9
9
|
return state;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Creates new Pilet API extensions for creating a Redux state container.
|
|
13
13
|
*/
|
|
14
|
-
function createReduxApi(config) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var initialState = {
|
|
21
|
-
stores: {},
|
|
22
|
-
};
|
|
14
|
+
function createReduxApi(config = {}) {
|
|
15
|
+
const { reducer = defaultReducer, enhancer } = config;
|
|
16
|
+
const otherReducers = {};
|
|
17
|
+
const initialState = { stores: {} };
|
|
18
|
+
const store = (0, redux_1.createStore)(createReducer(), enhancer);
|
|
19
|
+
const provider = (0, react_1.createElement)(react_redux_1.Provider, { store });
|
|
23
20
|
function createReducer() {
|
|
24
|
-
return
|
|
25
|
-
var _a, _b;
|
|
26
|
-
if (state === void 0) { state = initialState; }
|
|
21
|
+
return (state = initialState, action) => {
|
|
27
22
|
switch (action.type) {
|
|
28
23
|
case 'create-store': {
|
|
29
|
-
|
|
30
|
-
return
|
|
24
|
+
const stores = state.stores;
|
|
25
|
+
return Object.assign(Object.assign({}, state), { stores: Object.assign(Object.assign({}, stores), { [action.name]: action.value }) });
|
|
31
26
|
}
|
|
32
27
|
case 'destroy-store': {
|
|
33
|
-
|
|
34
|
-
return
|
|
28
|
+
const _a = state.stores, _b = action.name, _ = _a[_b], stores = (0, tslib_1.__rest)(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
29
|
+
return Object.assign(Object.assign({}, state), { stores: Object.assign({}, stores) });
|
|
35
30
|
}
|
|
36
31
|
case 'change-store': {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
const reducer = otherReducers[action.name];
|
|
33
|
+
const oldState = state.stores[action.name];
|
|
34
|
+
const newState = reducer(oldState, action.action);
|
|
40
35
|
if (oldState !== newState) {
|
|
41
|
-
return
|
|
36
|
+
return Object.assign(Object.assign({}, state), { stores: Object.assign(Object.assign({}, state.stores), { [action.name]: newState }) });
|
|
42
37
|
}
|
|
43
38
|
return state;
|
|
44
39
|
}
|
|
@@ -48,29 +43,27 @@ function createReduxApi(config) {
|
|
|
48
43
|
}
|
|
49
44
|
};
|
|
50
45
|
}
|
|
51
|
-
return
|
|
46
|
+
return (context) => {
|
|
52
47
|
context.includeProvider(provider);
|
|
53
|
-
return
|
|
54
|
-
createReduxStore
|
|
55
|
-
|
|
48
|
+
return (_, meta) => ({
|
|
49
|
+
createReduxStore(reducer) {
|
|
50
|
+
const name = meta.name;
|
|
56
51
|
otherReducers[name] = reducer;
|
|
57
52
|
store.dispatch({
|
|
58
53
|
type: 'create-store',
|
|
59
|
-
name
|
|
54
|
+
name,
|
|
60
55
|
value: reducer(undefined, { type: '$init' }),
|
|
61
56
|
});
|
|
62
|
-
|
|
57
|
+
const dispatch = (action) => ({
|
|
63
58
|
type: 'change-store',
|
|
64
|
-
name
|
|
65
|
-
action
|
|
66
|
-
});
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
})(component);
|
|
71
|
-
};
|
|
59
|
+
name,
|
|
60
|
+
action,
|
|
61
|
+
});
|
|
62
|
+
return (component) => (0, react_redux_1.connect)((state) => ({ state: state.stores[name] }), {
|
|
63
|
+
dispatch,
|
|
64
|
+
})(component);
|
|
72
65
|
},
|
|
73
|
-
});
|
|
66
|
+
});
|
|
74
67
|
};
|
|
75
68
|
}
|
|
76
69
|
exports.createReduxApi = createReduxApi;
|
package/lib/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;;AAAA
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;;AAAA,iCAAsC;AAEtC,6CAAgD;AAChD,iCAA4D;AAyB5D,SAAS,cAAc,CAAI,KAAQ;IACjC,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,SAAsB,EAAE;IACrD,MAAM,EAAE,OAAO,GAAG,cAAc,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IACtD,MAAM,aAAa,GAAG,EAAE,CAAC;IACzB,MAAM,YAAY,GAAoB,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IACrD,MAAM,KAAK,GAAG,IAAA,mBAAW,EAAC,aAAa,EAAkB,EAAE,QAAQ,CAAC,CAAC;IACrE,MAAM,QAAQ,GAA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AC,CAAC;QAElC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;YACnB,gBAAgB,CAAC,OAAO;gBACtB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;gBACvB,aAAa,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;gBAC9B,KAAK,CAAC,QAAQ,CAAC;oBACb,IAAI,EAAE,cAAc;oBACpB,IAAI;oBACJ,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;iBAC7C,CAAC,CAAC;gBACH,MAAM,QAAQ,GAAG,CAAC,MAAW,EAAE,EAAE,CAAC,CAAC;oBACjC,IAAI,EAAE,cAAc;oBACpB,IAAI;oBACJ,MAAM;iBACP,CAAC,CAAC;gBACH,OAAO,CAAC,SAAS,EAAE,EAAE,CACnB,IAAA,qBAAO,EAAwD,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;oBACzG,QAAQ;iBACT,CAAC,CAAC,SAAS,CAAQ,CAAC;YACzB,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AA7ED,wCA6EC"}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./create"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./create"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./types"), exports);
|
|
6
6
|
//# 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,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wDAAyB;AACzB,uDAAwB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-redux",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0-alpha.3154",
|
|
4
4
|
"description": "Plugin for the integration of Redux in a Piral instance.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral",
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/react-redux": "^5.0.19",
|
|
50
50
|
"@types/redux": "^3.6.0",
|
|
51
|
-
"piral-core": "^0.
|
|
51
|
+
"piral-core": "^0.14.0-alpha.3154"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"piral-core": "0.
|
|
54
|
+
"piral-core": "0.14.x"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "bc6cc60a59e6a8b1a154d187883cb794e8609939"
|
|
57
57
|
}
|
package/src/create.ts
CHANGED
|
@@ -36,11 +36,9 @@ function defaultReducer<T>(state: T): T {
|
|
|
36
36
|
export function createReduxApi(config: ReduxConfig = {}): PiralPlugin<PiletReduxApi> {
|
|
37
37
|
const { reducer = defaultReducer, enhancer } = config;
|
|
38
38
|
const otherReducers = {};
|
|
39
|
+
const initialState: PiralReduxState = { stores: {} };
|
|
39
40
|
const store = createStore(createReducer() as Reducer<any>, enhancer);
|
|
40
41
|
const provider = createElement(Provider, { store });
|
|
41
|
-
const initialState: PiralReduxState = {
|
|
42
|
-
stores: {},
|
|
43
|
-
};
|
|
44
42
|
|
|
45
43
|
function createReducer() {
|
|
46
44
|
return (state: PiralReduxState = initialState, action: ReducerUnion<PiralReduxActions>): PiralReduxState => {
|