Skip to content

Commit 669c627

Browse files
committed
perf(size): minify type symbol
1 parent 846e340 commit 669c627

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

src/helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const consumerAction = (
3333
modelName: modelContext.modelName,
3434
newState: null,
3535
params,
36-
type: 'outer'
36+
type: 'o'
3737
}
3838
return await applyMiddlewares(actionMiddlewares, context)
3939
}

src/index.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ interface BaseContext<S = {}, P = any> {
9696

9797
interface InnerContext<S = {}> extends BaseContext<S> {
9898
// Actions with function type context will always invoke current component's reload.
99-
type?: 'function' | 'outer' | 'class' | 'useModel'
99+
// f -> function, o -> outer, c -> class, u -> useModel
100+
type?: 'f' | 'o' | 'c' | 'u'
100101
__hash?: string
101102
}
102103

src/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function useModel<S>(
5151
modelName: '__' + storeId,
5252
newState: {},
5353
params: undefined,
54-
type: 'useModel'
54+
type: 'u'
5555
}
5656

5757
if (typeof state === 'function') {
@@ -268,7 +268,7 @@ const getState = (modelName: keyof typeof Global.State) => {
268268

269269
const getActions = (
270270
modelName: string,
271-
baseContext: Partial<Context> = { type: 'outer' }
271+
baseContext: Partial<Context> = { type: 'o' }
272272
) => {
273273
const updaters: any = {}
274274
Object.keys(Global.Actions[modelName]).forEach(
@@ -317,7 +317,7 @@ const useStore = (modelName: string, selector?: Function) => {
317317

318318
const updaters = getActions(modelName, {
319319
__hash: hash.current,
320-
type: 'function'
320+
type: 'f'
321321
})
322322
return [
323323
selector ? selector(getState(modelName)) : getState(modelName),

src/middlewares.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const setNewState: Middleware = async (context, restMiddlewares) => {
7777
}
7878
})
7979
}
80-
if (newState || type === 'useModel') {
80+
if (newState || type === 'u') {
8181
setPartialState(modelName, newState || {})
8282
return await next(restMiddlewares)
8383
}
@@ -87,7 +87,7 @@ const stateUpdater: Middleware = async (context, restMiddlewares) => {
8787
const { modelName, next, Global, __hash } = context
8888
const setter = Global.Setter.functionSetter[modelName]
8989
if (
90-
context.type === 'function' &&
90+
context.type === 'f' &&
9191
__hash &&
9292
setter &&
9393
setter[__hash] &&

0 commit comments

Comments
 (0)