Skip to content

Commit

Permalink
refactor: replace modifier from 'public static' to 'protected' for mo…
Browse files Browse the repository at this point in the history
…delStore
  • Loading branch information
geekact committed Oct 20, 2023
1 parent f508839 commit 7abce13
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/api/use-isolate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useMemo, useRef, useState } from 'react';
import { DestroyLoadingAction, DESTROY_LOADING } from '../actions/loading';
import { loadingStore } from '../store/loadingStore';
import { ModelStore, modelStore } from '../store/modelStore';
import { modelStore } from '../store/modelStore';
import { cloneModel } from '../model/cloneModel';
import { Model } from '../model/types';

Expand Down Expand Up @@ -141,7 +141,7 @@ const useDevName = (model: Model, count: number, err: Error) => {
};

const unmountModel = (modelName: string) => {
ModelStore.removeReducer.call(modelStore, modelName);
modelStore['removeReducer'](modelName);
loadingStore.dispatch<DestroyLoadingAction>({
type: DESTROY_LOADING,
model: modelName,
Expand Down
5 changes: 2 additions & 3 deletions src/model/defineModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseState, stringifyState } from '../utils/serialize';
import { deepEqual } from '../utils/deepEqual';
import { EnhancedAction, enhanceAction } from './enhanceAction';
import { EnhancedEffect, enhanceEffect } from './enhanceEffect';
import { ModelStore, modelStore } from '../store/modelStore';
import { modelStore } from '../store/modelStore';
import { createReducer } from '../redux/createReducer';
import { composeGetter, defineGetter } from '../utils/getter';
import { getMethodCategory } from '../utils/getMethodCategory';
Expand Down Expand Up @@ -267,8 +267,7 @@ export const defineModel = <
});
}

ModelStore.appendReducer.call(
modelStore,
modelStore['appendReducer'](
uniqueName,
createReducer({
name: uniqueName,
Expand Down
8 changes: 2 additions & 6 deletions src/store/modelStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,7 @@ export class ModelStore extends StoreBasic<Record<string, any>> {
};
}

public static appendReducer(
this: ModelStore,
key: string,
consumer: Reducer,
): void {
protected appendReducer(key: string, consumer: Reducer): void {
const store = this.origin;
const consumers = this.consumers;
const exists = store && consumers.hasOwnProperty(key);
Expand All @@ -209,7 +205,7 @@ export class ModelStore extends StoreBasic<Record<string, any>> {
store && !exists && store.replaceReducer(this.reducer);
}

public static removeReducer(this: ModelStore, key: string): void {
protected removeReducer(key: string): void {
const store = this.origin;
const consumers = this.consumers;

Expand Down
5 changes: 2 additions & 3 deletions test/lifecycle.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sleep from 'sleep-promise';
import { cloneModel, defineModel, memoryStorage, store } from '../src';
import { PersistSchema } from '../src/persist/PersistItem';
import { ModelStore } from '../src/store/modelStore';

describe('onInit', () => {
afterEach(() => {
Expand Down Expand Up @@ -215,7 +214,7 @@ describe('onDestroy', () => {

model.update();
expect(spy).toBeCalledTimes(0);
ModelStore.removeReducer.call(store, model.name);
store['removeReducer'](model.name);
expect(spy).toBeCalledTimes(1);
spy.mockRestore();
});
Expand All @@ -241,7 +240,7 @@ describe('onDestroy', () => {
model.update();
expect(destroySpy).toBeCalledTimes(0);
expect(changeSpy).toBeCalledTimes(1);
ModelStore.removeReducer.call(store, model.name);
store['removeReducer'](model.name);
expect(destroySpy).toBeCalledTimes(1);
expect(changeSpy).toBeCalledTimes(1);
destroySpy.mockRestore();
Expand Down

0 comments on commit 7abce13

Please sign in to comment.