Skip to content

Commit

Permalink
fix(mutative): upgrade mutative to 0.42.0
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib committed Feb 6, 2023
1 parent 1819621 commit 115da64
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 34 deletions.
2 changes: 1 addition & 1 deletion packages/usm-redux/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"author": "unadlib",
"license": "MIT",
"dependencies": {
"mutative": "^0.4.1",
"mutative": "^0.4.2",
"redux": "^4.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/usm-redux/src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export const subscriptionsKey: unique symbol = Symbol('subscriptions');
export const stateKey: unique symbol = Symbol('state');
export const bootstrappedKey: unique symbol = Symbol('bootstrapped');
export const identifierKey: unique symbol = Symbol('identifier');
export const enableAutoFreezeKey: unique symbol = Symbol('enableAutoFreeze');
export const strictKey: unique symbol = Symbol('strict');
export const enablePatchesKey: unique symbol = Symbol('enablePatches');
20 changes: 13 additions & 7 deletions packages/usm-redux/src/createStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
identifierKey,
subscriptionsKey,
usm,
enableAutoFreezeKey,
strictKey,
enablePatchesKey,
} from './constant';
import { getStagedState } from './utils/index';
Expand All @@ -40,7 +40,7 @@ export const createStore = (
`'createStore' options should be a object with a property 'modules'`
);
}
const enableAutoFreeze = options.strict ?? __DEV__;
const strict = options.strict ?? false;
const enablePatches = config.enablePatches ?? false;
const identifiers = new Set<string>();
const reducers: ReducersMapObject = {};
Expand Down Expand Up @@ -109,9 +109,10 @@ export const createStore = (
},
});
}
const initState = enableAutoFreeze
const initState = strict
? create({ ...service[stateKey] }, () => {}, {
enableAutoFreeze,
strict,
enableAutoFreeze: strict,
})
: service[stateKey];

Expand Down Expand Up @@ -145,7 +146,7 @@ export const createStore = (
const stagedState = getStagedState();
if (stagedState) return stagedState[identifier];
const currentState = this[storeKey]?.getState()[identifier];
if (enableAutoFreeze && !Object.isFrozen(currentState)) {
if (strict && !Object.isFrozen(currentState)) {
return Object.freeze(currentState);
}
return currentState;
Expand All @@ -159,10 +160,15 @@ export const createStore = (
enumerable: false,
value: identifier,
},
[enableAutoFreezeKey]: {
[strictKey]: {
configurable: false,
enumerable: false,
value: enableAutoFreeze,
value: strict,
},
[strictKey]: {
configurable: false,
enumerable: false,
value: strict,
},
[enablePatchesKey]: {
configurable: false,
Expand Down
10 changes: 6 additions & 4 deletions packages/usm-redux/src/decorators/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
storeKey,
identifierKey,
usm,
enableAutoFreezeKey,
strictKey,
enablePatchesKey,
} from '../constant';
import { getStagedState, setStagedState } from '../utils/index';
Expand Down Expand Up @@ -33,15 +33,17 @@ export const action = (
fn.apply(this, args);
};
const enablePatches = this[enablePatchesKey];
const enableAutoFreeze = this[enableAutoFreezeKey];
const strict = this[strictKey];
if (enablePatches) {
[state, patches, inversePatches] = create(lastState, recipe, {
enablePatches: true,
enableAutoFreeze,
strict,
enableAutoFreeze: strict,
});
} else {
state = create(lastState, recipe, {
enableAutoFreeze,
strict,
enableAutoFreeze: strict,
});
}
setStagedState(undefined);
Expand Down
4 changes: 2 additions & 2 deletions packages/usm-redux/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
bootstrappedKey,
usm,
identifierKey,
enableAutoFreezeKey,
strictKey,
enablePatchesKey,
} from './constant';

Expand All @@ -26,7 +26,7 @@ export interface Service<T extends Record<string, any> = Record<string, any>> {
name?: string;
readonly [bootstrappedKey]: boolean;
readonly [identifierKey]: string;
readonly [enableAutoFreezeKey]: boolean;
readonly [strictKey]: boolean;
readonly [enablePatchesKey]: boolean;
readonly [stateKey]: T;
readonly [storeKey]: Store<T>;
Expand Down
2 changes: 1 addition & 1 deletion packages/usm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"author": "unadlib",
"license": "MIT",
"dependencies": {
"mutative": "^0.4.1"
"mutative": "^0.4.2"
}
}
2 changes: 1 addition & 1 deletion packages/usm/src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const storeKey: unique symbol = Symbol('store');
export const subscriptionsKey: unique symbol = Symbol('subscriptions');
export const stateKey: unique symbol = Symbol('state');
export const identifierKey: unique symbol = Symbol('identifier');
export const enableAutoFreezeKey: unique symbol = Symbol('enableAutoFreeze');
export const strictKey: unique symbol = Symbol('strict');
export const enablePatchesKey: unique symbol = Symbol('enablePatches');
export const changeStateKey: unique symbol = Symbol('changeState');
export const bootstrappedKey: unique symbol = Symbol('bootstrapped');
15 changes: 8 additions & 7 deletions packages/usm/src/createStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
storeKey,
bootstrappedKey,
subscriptionsKey,
enableAutoFreezeKey,
strictKey,
enablePatchesKey,
} from './constant';
import {
Expand All @@ -29,7 +29,7 @@ export const createStore = (
`'createStore' options should be a object with a property 'modules'`
);
}
const enableAutoFreeze = options.strict ?? __DEV__;
const strict = options.strict ?? __DEV__;
const enablePatches = config.enablePatches ?? false;
let state: Record<string, any> = {};
const subscriptions: Subscription[] = [];
Expand Down Expand Up @@ -120,9 +120,10 @@ export const createStore = (
},
});
}
state[identifier] = enableAutoFreeze
state[identifier] = strict
? create({ ...service[stateKey] }, () => {}, {
enableAutoFreeze,
strict,
enableAutoFreeze: strict,
})
: service[stateKey];
Object.assign(descriptors, {
Expand All @@ -134,7 +135,7 @@ export const createStore = (
if (stagedState) return stagedState[this[identifierKey]];
const currentState =
this[storeKey]?.getState()[this[identifierKey]];
if (enableAutoFreeze && !Object.isFrozen(currentState)) {
if (strict && !Object.isFrozen(currentState)) {
return Object.freeze(currentState);
}
return currentState;
Expand All @@ -148,10 +149,10 @@ export const createStore = (
enumerable: false,
value: identifier,
},
[enableAutoFreezeKey]: {
[strictKey]: {
configurable: false,
enumerable: false,
value: enableAutoFreeze,
value: strict,
},
[enablePatchesKey]: {
configurable: false,
Expand Down
10 changes: 6 additions & 4 deletions packages/usm/src/decorators/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
identifierKey,
usm,
enablePatchesKey,
enableAutoFreezeKey,
strictKey,
} from '../constant';
import { getStagedState, setStagedState } from '../utils/index';

Expand All @@ -31,15 +31,17 @@ export const action = (
fn.apply(this, args);
};
const enablePatches = this[enablePatchesKey];
const enableAutoFreeze = this[enableAutoFreezeKey];
const strict = this[strictKey];
if (enablePatches) {
[state, patches, inversePatches] = create(lastState, recipe, {
enablePatches: true,
enableAutoFreeze,
strict,
enableAutoFreeze: strict,
});
} else {
state = create(lastState, recipe, {
enableAutoFreeze,
strict,
enableAutoFreeze: strict,
});
}
setStagedState(undefined);
Expand Down
4 changes: 2 additions & 2 deletions packages/usm/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
identifierKey,
bootstrappedKey,
usm,
enableAutoFreezeKey,
strictKey,
enablePatchesKey,
} from './constant';

Expand All @@ -29,7 +29,7 @@ export interface Store<T = Record<string, any>> {
export interface Service<T extends Record<string, any> = Record<string, any>> {
name?: string;
readonly [identifierKey]: string;
readonly [enableAutoFreezeKey]: boolean;
readonly [strictKey]: boolean;
readonly [enablePatchesKey]: boolean;
readonly [bootstrappedKey]: boolean;
readonly [stateKey]: T;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5641,10 +5641,10 @@ multimatch@^5.0.0:
arrify "^2.0.1"
minimatch "^3.0.4"

mutative@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/mutative/-/mutative-0.4.1.tgz#7e71eb01ec24e5a8b031079588d5455fa16786e7"
integrity sha512-V3z99IFyMfmGoEFoYWXgyEzPis3nsqu8SceQFgR2dKm+Rzn8lQBle/VjPF9sEh1xABxgJvCicQ82q0iwdj4E+A==
mutative@^0.4.2:
version "0.4.2"
resolved "https://registry.yarnpkg.com/mutative/-/mutative-0.4.2.tgz#dacdae80c32f09b380979cfc534c4274f5a46079"
integrity sha512-zAWi/R6mShx7Dr6SnT61Z2Wf2TKVbAVGPzoS8vbr/fK5X0e7hD4pglpLSCWNtA0jh3RoS0QsdjJCywbQpwef5g==

[email protected]:
version "0.0.7"
Expand Down

0 comments on commit 115da64

Please sign in to comment.