@tramvai/state 2.70.0 → 2.72.0
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/connect/Provider.es.js +8 -0
- package/lib/connect/Provider.js +12 -0
- package/lib/connect/Subscription.es.js +37 -0
- package/lib/connect/Subscription.js +41 -0
- package/lib/connect/connectAdvanced.es.js +159 -0
- package/lib/connect/connectAdvanced.js +170 -0
- package/lib/connect/context.es.js +6 -0
- package/lib/connect/context.js +11 -0
- package/lib/connect/hooks/useActions.es.js +17 -0
- package/lib/connect/hooks/useActions.js +25 -0
- package/lib/connect/hooks/useConsumerContext.es.js +12 -0
- package/lib/connect/hooks/useConsumerContext.js +16 -0
- package/lib/connect/hooks/useSelector.es.js +53 -0
- package/lib/connect/hooks/useSelector.js +63 -0
- package/lib/connect/hooks/useStore.es.js +37 -0
- package/lib/connect/hooks/useStore.js +41 -0
- package/lib/connect/hooks/useStoreSelector.es.js +11 -0
- package/lib/connect/hooks/useStoreSelector.js +15 -0
- package/lib/connect/index.es.js +91 -0
- package/lib/connect/index.js +107 -0
- package/lib/connect/scheduling.es.js +12 -0
- package/lib/connect/scheduling.js +16 -0
- package/lib/connect/selectorFactory.es.js +95 -0
- package/lib/connect/selectorFactory.js +101 -0
- package/lib/connect/toProps/mapContextToProps.es.js +23 -0
- package/lib/connect/toProps/mapContextToProps.js +34 -0
- package/lib/connect/toProps/mapStateToProps.es.js +17 -0
- package/lib/connect/toProps/mapStateToProps.js +27 -0
- package/lib/connect/toProps/mergeProps.es.js +36 -0
- package/lib/connect/toProps/mergeProps.js +42 -0
- package/lib/connect/toProps/wrapMapToProps.es.js +73 -0
- package/lib/connect/toProps/wrapMapToProps.js +85 -0
- package/lib/connect/utils/verifyFunction.es.js +10 -0
- package/lib/connect/utils/verifyFunction.js +18 -0
- package/lib/connect/utils/verifyMapToProps.es.js +20 -0
- package/lib/connect/utils/verifyMapToProps.js +28 -0
- package/lib/connect/utils/verifyPlainObject.es.js +10 -0
- package/lib/connect/utils/verifyPlainObject.js +18 -0
- package/lib/createEvent/createEvent.es.js +22 -0
- package/lib/createEvent/createEvent.js +31 -0
- package/lib/createReducer/createReducer.es.js +60 -0
- package/lib/createReducer/createReducer.js +64 -0
- package/lib/devTools/constants.es.js +3 -0
- package/lib/devTools/constants.js +7 -0
- package/lib/{index_middleware.es.js → devTools/devTools.es.js} +2 -36
- package/lib/{index_middleware.js → devTools/devTools.js} +4 -40
- package/lib/devTools/index.es.js +21 -0
- package/lib/devTools/index.js +23 -0
- package/lib/devTools/middleware.es.js +37 -0
- package/lib/devTools/middleware.js +45 -0
- package/lib/dispatcher/childDispatcherContext.es.js +46 -0
- package/lib/dispatcher/childDispatcherContext.js +50 -0
- package/lib/dispatcher/dispatcher.es.js +105 -0
- package/lib/dispatcher/dispatcher.js +110 -0
- package/lib/dispatcher/dispatcherContext.es.js +279 -0
- package/lib/dispatcher/dispatcherContext.js +288 -0
- package/lib/dispatcher/storeSubscribe.es.js +8 -0
- package/lib/dispatcher/storeSubscribe.js +12 -0
- package/lib/index.es.js +16 -1246
- package/lib/index.js +36 -1281
- package/lib/logger.es.js +3 -0
- package/lib/logger.js +7 -0
- package/lib/stores/BaseStore.es.js +53 -0
- package/lib/stores/BaseStore.js +61 -0
- package/lib/stores/SimpleEmitter.es.js +30 -0
- package/lib/stores/SimpleEmitter.js +34 -0
- package/package.json +6 -7
package/lib/logger.es.js
ADDED
package/lib/logger.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import pick from '@tinkoff/utils/object/pick';
|
|
2
|
+
import { SimpleEmitter } from './SimpleEmitter.es.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated метод устарел, в замен этого API используй createReducer, который новее и лучше маштабируется
|
|
6
|
+
*/
|
|
7
|
+
class BaseStore extends SimpleEmitter {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.state = Object.create(null);
|
|
11
|
+
this.hydrateKeys = Object.create(null);
|
|
12
|
+
}
|
|
13
|
+
getState() {
|
|
14
|
+
return this.state;
|
|
15
|
+
}
|
|
16
|
+
dehydrate() {
|
|
17
|
+
return pick(Object.keys(this.hydrateKeys), this.state);
|
|
18
|
+
}
|
|
19
|
+
rehydrate(state) {
|
|
20
|
+
this.setStateSilently(state);
|
|
21
|
+
}
|
|
22
|
+
writeHydrateKeys(state) {
|
|
23
|
+
Object.keys(state).forEach((key) => {
|
|
24
|
+
this.hydrateKeys[key] = true;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
// eslint-disable-next-line class-methods-use-this
|
|
28
|
+
shouldStateUpdate(nextState) {
|
|
29
|
+
return !!Object.keys(nextState).length;
|
|
30
|
+
}
|
|
31
|
+
setState(state, force = false) {
|
|
32
|
+
if (force || this.shouldStateUpdate(state)) {
|
|
33
|
+
this.setStateSilently(state);
|
|
34
|
+
this.emit('change');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
setStateSilently(state) {
|
|
38
|
+
this.state = { ...this.state, ...state };
|
|
39
|
+
this.writeHydrateKeys(state);
|
|
40
|
+
}
|
|
41
|
+
replaceState(state) {
|
|
42
|
+
this.replaceStateSilently(state);
|
|
43
|
+
this.emit('change');
|
|
44
|
+
}
|
|
45
|
+
// @deprecated нужно использовать replaceState
|
|
46
|
+
replaceStateSilently(state) {
|
|
47
|
+
this.state = state;
|
|
48
|
+
this.hydrateKeys = Object.create(null);
|
|
49
|
+
this.writeHydrateKeys(state);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { BaseStore };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var pick = require('@tinkoff/utils/object/pick');
|
|
6
|
+
var SimpleEmitter = require('./SimpleEmitter.js');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var pick__default = /*#__PURE__*/_interopDefaultLegacy(pick);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated метод устарел, в замен этого API используй createReducer, который новее и лучше маштабируется
|
|
14
|
+
*/
|
|
15
|
+
class BaseStore extends SimpleEmitter.SimpleEmitter {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments);
|
|
18
|
+
this.state = Object.create(null);
|
|
19
|
+
this.hydrateKeys = Object.create(null);
|
|
20
|
+
}
|
|
21
|
+
getState() {
|
|
22
|
+
return this.state;
|
|
23
|
+
}
|
|
24
|
+
dehydrate() {
|
|
25
|
+
return pick__default["default"](Object.keys(this.hydrateKeys), this.state);
|
|
26
|
+
}
|
|
27
|
+
rehydrate(state) {
|
|
28
|
+
this.setStateSilently(state);
|
|
29
|
+
}
|
|
30
|
+
writeHydrateKeys(state) {
|
|
31
|
+
Object.keys(state).forEach((key) => {
|
|
32
|
+
this.hydrateKeys[key] = true;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
// eslint-disable-next-line class-methods-use-this
|
|
36
|
+
shouldStateUpdate(nextState) {
|
|
37
|
+
return !!Object.keys(nextState).length;
|
|
38
|
+
}
|
|
39
|
+
setState(state, force = false) {
|
|
40
|
+
if (force || this.shouldStateUpdate(state)) {
|
|
41
|
+
this.setStateSilently(state);
|
|
42
|
+
this.emit('change');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
setStateSilently(state) {
|
|
46
|
+
this.state = { ...this.state, ...state };
|
|
47
|
+
this.writeHydrateKeys(state);
|
|
48
|
+
}
|
|
49
|
+
replaceState(state) {
|
|
50
|
+
this.replaceStateSilently(state);
|
|
51
|
+
this.emit('change');
|
|
52
|
+
}
|
|
53
|
+
// @deprecated нужно использовать replaceState
|
|
54
|
+
replaceStateSilently(state) {
|
|
55
|
+
this.state = state;
|
|
56
|
+
this.hydrateKeys = Object.create(null);
|
|
57
|
+
this.writeHydrateKeys(state);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
exports.BaseStore = BaseStore;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class SimpleEmitter {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.listeners = [];
|
|
4
|
+
}
|
|
5
|
+
emit(name) {
|
|
6
|
+
this.listeners.forEach((listener) => {
|
|
7
|
+
listener();
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
addListener(event, fn) {
|
|
11
|
+
this.listeners.push(fn);
|
|
12
|
+
}
|
|
13
|
+
on(event, fn) {
|
|
14
|
+
this.addListener(event, fn);
|
|
15
|
+
}
|
|
16
|
+
removeListener(event, fn) {
|
|
17
|
+
const listeners = [];
|
|
18
|
+
for (let i = 0; i < this.listeners.length; i++) {
|
|
19
|
+
if (this.listeners[i] !== fn) {
|
|
20
|
+
listeners.push(this.listeners[i]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
this.listeners = listeners;
|
|
24
|
+
}
|
|
25
|
+
off(event, fn) {
|
|
26
|
+
this.removeListener(event, fn);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { SimpleEmitter };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
class SimpleEmitter {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.listeners = [];
|
|
8
|
+
}
|
|
9
|
+
emit(name) {
|
|
10
|
+
this.listeners.forEach((listener) => {
|
|
11
|
+
listener();
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
addListener(event, fn) {
|
|
15
|
+
this.listeners.push(fn);
|
|
16
|
+
}
|
|
17
|
+
on(event, fn) {
|
|
18
|
+
this.addListener(event, fn);
|
|
19
|
+
}
|
|
20
|
+
removeListener(event, fn) {
|
|
21
|
+
const listeners = [];
|
|
22
|
+
for (let i = 0; i < this.listeners.length; i++) {
|
|
23
|
+
if (this.listeners[i] !== fn) {
|
|
24
|
+
listeners.push(this.listeners[i]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
this.listeners = listeners;
|
|
28
|
+
}
|
|
29
|
+
off(event, fn) {
|
|
30
|
+
this.removeListener(event, fn);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.SimpleEmitter = SimpleEmitter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/state",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.72.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -13,14 +13,13 @@
|
|
|
13
13
|
"url": "git@github.com:Tinkoff/tramvai.git"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
|
-
"build": "tramvai-build --
|
|
17
|
-
"watch": "tsc -w"
|
|
18
|
-
"build-for-publish": "true"
|
|
16
|
+
"build": "tramvai-build --forPublish --preserveModules",
|
|
17
|
+
"watch": "tsc -w"
|
|
19
18
|
},
|
|
20
19
|
"dependencies": {
|
|
21
|
-
"@tinkoff/react-hooks": "0.1.
|
|
20
|
+
"@tinkoff/react-hooks": "0.1.5",
|
|
22
21
|
"@tinkoff/utils": "^2.1.2",
|
|
23
|
-
"@tramvai/types-actions-state-context": "2.
|
|
22
|
+
"@tramvai/types-actions-state-context": "2.72.0",
|
|
24
23
|
"@types/hoist-non-react-statics": "^3.3.1",
|
|
25
24
|
"invariant": "^2.2.4",
|
|
26
25
|
"react-is": ">=17",
|
|
@@ -35,7 +34,7 @@
|
|
|
35
34
|
},
|
|
36
35
|
"devDependencies": {
|
|
37
36
|
"@reatom/core": "^1.1.5",
|
|
38
|
-
"@tramvai/core": "2.
|
|
37
|
+
"@tramvai/core": "2.72.0",
|
|
39
38
|
"@types/invariant": "^2.2.31",
|
|
40
39
|
"@types/react-is": "^17.0.0",
|
|
41
40
|
"@types/use-sync-external-store": "^0.0.3",
|