Skip to content

Commit 95c50b7

Browse files
committed
0.4
1 parent 81c6c3f commit 95c50b7

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mobz",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "zustand style mobx api",
55
"main": "./dist/mobz.cjs.js",
66
"module": "./dist/mobz.es.js",

src/mobz.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,27 @@ export function useComputedRaw<T>(getter: () => T, options?: IComputedValueOptio
2828

2929
export type IAutoEffectCtx = {
3030
setStopSignal: (s: () => Promise<void>) => void
31+
first: boolean
3132
}
3233
export type IAutoEffectOptions = {
3334
stopSignal?: () => Promise<void>
3435
}
3536
export function useAutoEffect(effect: (ctx: IAutoEffectCtx) => any, options?: IAutorunOptions & IAutoEffectOptions) {
3637
useEffect(() => {
3738
let stopSignal = options?.stopSignal
38-
const ctx: IAutoEffectCtx = {
39+
let first = true
40+
const ctx: IAutoEffectCtx = {
3941
setStopSignal(s) {
4042
stopSignal = s
43+
},
44+
get first() {
45+
return first
4146
}
4247
}
43-
const d = autorun(() => effect(ctx), options)
48+
const d = autorun(() => {
49+
effect(ctx)
50+
first = false
51+
}, options)
4452
if (typeof stopSignal === 'function') {
4553
(async () => {
4654
await stopSignal()
@@ -102,8 +110,8 @@ function buildActions<T extends object>(obj: T) {
102110
}
103111

104112
function bindActions(obj: any, actions: MobzAction<any>[]) {
105-
for (const action of actions) {
106-
action.fn = action.fn.bind(obj)
113+
for (const a of actions) {
114+
a.fn = a.fn.bind(obj)
107115
}
108116
}
109117

0 commit comments

Comments
 (0)