Skip to content

Commit fcb53b9

Browse files
feat: Release effectOn & prepare for v6.0.0 (#813)
* feat: Stabilize `effectOn` & prepare for 6.0.0 - Refactors `unstable_effectOn` -> `effectOn` - Updated docs - Bumps version to `6.0.0` todo: - [ ] Publish a copy of existing docs to `https://easy-peasy-v5.vercel.app/` * docs: remove last reference to "unstable" --------- Co-authored-by: Peter Weinberg <pweinberg633@gmail.com>
1 parent 90db988 commit fcb53b9

File tree

16 files changed

+109
-138
lines changed

16 files changed

+109
-138
lines changed

examples/kanban/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"type-check": "tsc"
1313
},
1414
"dependencies": {
15-
"easy-peasy": "5.1.0",
15+
"easy-peasy": "6.0.0",
1616
"react": "^18.2.0",
1717
"react-dom": "^18.2.0"
1818
},

examples/nextjs-todo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12-
"easy-peasy": "5.2.0",
12+
"easy-peasy": "6.0.0",
1313
"next": "13.2.4",
1414
"react": "18.2.0",
1515
"react-dom": "18.2.0"

examples/reduxtagram/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"dependencies": {
1515
"@types/react-transition-group": "^4.4.5",
16-
"easy-peasy": "^5.1.0",
16+
"easy-peasy": "6.0.0",
1717
"nanoid": "^4.0.0",
1818
"react": "^18.2.0",
1919
"react-dom": "^18.2.0",

examples/simple-todo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"type-check": "tsc"
1212
},
1313
"dependencies": {
14-
"easy-peasy": "5.1.0",
14+
"easy-peasy": "6.0.0",
1515
"react": "^18.2.0",
1616
"react-dom": "^18.2.0"
1717
},

index.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ type ActionListenerTypes = ActionOn<any, any> | ThunkOn<any, any, any>;
9494
type ActionTypes =
9595
| ActionEmitterTypes
9696
| ActionListenerTypes
97-
| Unstable_EffectOn<any, any, any>;
97+
| EffectOn<any, any, any>;
9898

9999
interface ActionCreator<Payload = void> {
100100
(payload: Payload): void;
@@ -698,7 +698,7 @@ export function computed<
698698

699699
// #region EffectOn
700700

701-
export interface Unstable_EffectOn<
701+
export interface EffectOn<
702702
Model extends object = {},
703703
StoreModel extends object = {},
704704
Injections = any,
@@ -717,7 +717,7 @@ type Change<Resolvers extends StateResolvers<any, any>> = {
717717

718718
export type Dispose = () => any;
719719

720-
export function unstable_effectOn<
720+
export function effectOn<
721721
Model extends object = {},
722722
StoreModel extends object = {},
723723
Injections = any,
@@ -732,7 +732,7 @@ export function unstable_effectOn<
732732
change: Change<Resolvers>,
733733
helpers: Helpers<Model, StoreModel, Injections>,
734734
) => undefined | void | Dispose,
735-
): Unstable_EffectOn<Model, StoreModel, Injections>;
735+
): EffectOn<Model, StoreModel, Injections>;
736736

737737
// #endregion
738738

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "easy-peasy",
3-
"version": "5.2.1-alpha.0",
3+
"version": "6.0.0",
44
"description": "Vegetarian friendly state for React",
55
"license": "MIT",
66
"main": "dist/index.cjs.js",

src/helpers.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ export const actionOn = (targetResolver, fn, config) => ({
2121
[actionOnSymbol]: true,
2222
fn,
2323
targetResolver,
24-
config
24+
config,
2525
});
2626

2727
export const action = (fn, config) => ({
2828
[actionSymbol]: true,
2929
fn,
30-
config
30+
config,
3131
});
3232

3333
const defaultStateResolvers = [(state) => state];
@@ -47,7 +47,7 @@ export const computed = (fnOrStateResolvers, fn) => {
4747
};
4848
};
4949

50-
export function unstable_effectOn(dependencyResolvers, fn) {
50+
export function effectOn(dependencyResolvers, fn) {
5151
return {
5252
[effectOnSymbol]: true,
5353
dependencyResolvers,
@@ -82,5 +82,5 @@ export const thunk = (fn) => ({
8282
export const reducer = (fn, config) => ({
8383
[reducerSymbol]: true,
8484
fn,
85-
config
85+
config,
8686
});

tests/effect-on.test.js

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
createStore,
33
action,
4-
unstable_effectOn,
4+
effectOn,
55
thunk,
66
thunkOn,
77
actionOn,
@@ -36,7 +36,7 @@ test('fires when the dependencies change', () => {
3636
addTodo: action((state, payload) => {
3737
state.todos.push(payload);
3838
}),
39-
onTodosChanged: unstable_effectOn(
39+
onTodosChanged: effectOn(
4040
[(state) => state.todos, (state) => state.foo],
4141
() => {
4242
fired = true;
@@ -45,7 +45,7 @@ test('fires when the dependencies change', () => {
4545
});
4646

4747
// ACT
48-
store.getActions().addTodo('add unstable_effectOn api');
48+
store.getActions().addTodo('add effectOn api');
4949

5050
// ASSERT
5151
expect(fired).toBe(true);
@@ -69,7 +69,7 @@ test('does not fire when the dependencies have not changed', () => {
6969
setFoo: action((state, payload) => {
7070
state.foo = payload;
7171
}),
72-
onTodosChanged: unstable_effectOn([(state) => state.todos], () => {
72+
onTodosChanged: effectOn([(state) => state.todos], () => {
7373
fired = true;
7474
}),
7575
});
@@ -89,7 +89,7 @@ test('fires when store dependency changes', () => {
8989
setFired: action((state, payload) => {
9090
state.fired = payload;
9191
}),
92-
onTodosChanged: unstable_effectOn(
92+
onTodosChanged: effectOn(
9393
[(state, storeState) => storeState.todos],
9494
(actions) => {
9595
actions.setFired(true);
@@ -123,7 +123,7 @@ test('it receives the local actions', () => {
123123
setFired: action((state, payload) => {
124124
state.fired = payload;
125125
}),
126-
onTodosChanged: unstable_effectOn([(state) => state.todos], (actions) => {
126+
onTodosChanged: effectOn([(state) => state.todos], (actions) => {
127127
actions.setFired(true);
128128
}),
129129
});
@@ -144,7 +144,7 @@ test('it receives the local actions for nested model', () => {
144144
nested: {
145145
fired: false,
146146
todos: [],
147-
onTodosChanged: unstable_effectOn([(state) => state.todos], (actions) => {
147+
onTodosChanged: effectOn([(state) => state.todos], (actions) => {
148148
actions.setFired(true);
149149
}),
150150
addTodo: action((state, payload) => {
@@ -153,7 +153,7 @@ test('it receives the local actions for nested model', () => {
153153
setFired: action((state, payload) => {
154154
state.fired = payload;
155155
}),
156-
}
156+
},
157157
});
158158

159159
// ASSERT
@@ -184,12 +184,9 @@ test('change argument is as expected', () => {
184184
actions.setTwo(target.payload);
185185
},
186186
),
187-
onStateChanged: unstable_effectOn(
188-
[(state) => state.two],
189-
(actions, change) => {
190-
actualChange = change;
191-
},
192-
),
187+
onStateChanged: effectOn([(state) => state.two], (actions, change) => {
188+
actualChange = change;
189+
}),
193190
});
194191

195192
// ACT
@@ -216,7 +213,7 @@ test('getState is exposed in helpers', async () => {
216213
setString: action((state, payload) => {
217214
state.string = payload;
218215
}),
219-
onStateChanged: unstable_effectOn(
216+
onStateChanged: effectOn(
220217
[(state) => state.string],
221218
(actions, change, { getState }) => {
222219
actualState = getState();
@@ -245,7 +242,7 @@ test('getStoreState is exposed in helpers', async () => {
245242
setString: action((state, payload) => {
246243
state.string = payload;
247244
}),
248-
onStateChanged: unstable_effectOn(
245+
onStateChanged: effectOn(
249246
[(state) => state.string],
250247
(actions, change, { getStoreState }) => {
251248
actualStoreState = getStoreState();
@@ -276,7 +273,7 @@ test('meta values are exposed in helpers', async () => {
276273
setString: action((state, payload) => {
277274
state.string = payload;
278275
}),
279-
onStateChanged: unstable_effectOn(
276+
onStateChanged: effectOn(
280277
[(state) => state.string],
281278
(actions, change, { meta }) => {
282279
actualMeta = meta;
@@ -308,7 +305,7 @@ test('injections are exposed in helpers', async () => {
308305
setString: action((state, payload) => {
309306
state.string = payload;
310307
}),
311-
onStateChanged: unstable_effectOn(
308+
onStateChanged: effectOn(
312309
[(state) => state.string],
313310
(actions, change, helpers) => {
314311
actualInjections = helpers.injections;
@@ -338,7 +335,7 @@ test('dispatch is exposed in helpers', async () => {
338335
setString: action((state, payload) => {
339336
state.string = payload;
340337
}),
341-
onStateChanged: unstable_effectOn(
338+
onStateChanged: effectOn(
342339
[(state) => state.string],
343340
(actions, change, helpers) => {
344341
actualDispatch = helpers.dispatch;
@@ -363,7 +360,7 @@ test('getStoreActions are exposed in helpers', async () => {
363360
setString: action((state, payload) => {
364361
state.string = payload;
365362
}),
366-
onStateChanged: unstable_effectOn(
363+
onStateChanged: effectOn(
367364
[(state) => state.string],
368365
(actions, change, helpers) => {
369366
helpers.getStoreActions().nested.setString('three');
@@ -391,12 +388,9 @@ test('dispatches actions to represent a succeeded effect', () => {
391388
setNumber: action((state, payload) => {
392389
state.number = payload;
393390
}),
394-
onStateChanged: unstable_effectOn(
395-
[(state) => state.string],
396-
(actions) => {
397-
actions.setNumber(2);
398-
},
399-
),
391+
onStateChanged: effectOn([(state) => state.string], (actions) => {
392+
actions.setNumber(2);
393+
}),
400394
},
401395
};
402396
const trackActions = trackActionsMiddleware();
@@ -448,7 +442,7 @@ describe('errors', () => {
448442
doAsync: thunk(() => {
449443
throw err;
450444
}),
451-
onStateChanged: unstable_effectOn(
445+
onStateChanged: effectOn(
452446
[(state) => state.string],
453447
async (actions, change) => {
454448
await actions.doAsync(change.action.payload);
@@ -504,7 +498,7 @@ test('effects cannot be targetted by actionOn', async () => {
504498
setString: action((state, payload) => {
505499
state.string = payload;
506500
}),
507-
onStateChanged: unstable_effectOn([(state) => state.string], () => {
501+
onStateChanged: effectOn([(state) => state.string], () => {
508502
// do nothing
509503
}),
510504
invalidActionOn: actionOn(
@@ -535,7 +529,7 @@ test('effects cannot be targetted by thunkOn', async () => {
535529
setString: action((state, payload) => {
536530
state.string = payload;
537531
}),
538-
onStateChanged: unstable_effectOn([(state) => state.string], () => {
532+
onStateChanged: effectOn([(state) => state.string], () => {
539533
// do nothing
540534
}),
541535
invalidThunkOn: actionOn(
@@ -567,7 +561,7 @@ test('synchronous effect with synchronous dispose executes as expected', () => {
567561
setFoo: action((state, payload) => {
568562
state.foo = payload;
569563
}),
570-
onFooChange: unstable_effectOn([(state) => state.foo], () => {
564+
onFooChange: effectOn([(state) => state.foo], () => {
571565
executionId += 1;
572566
executions.push({ id: executionId, type: 'effect' });
573567
return () => {
@@ -601,7 +595,7 @@ test('synchronous effect with asynchronous dispose executes as expected', async
601595
setFoo: action((state, payload) => {
602596
state.foo = payload;
603597
}),
604-
onFooChange: unstable_effectOn([(state) => state.foo], () => {
598+
onFooChange: effectOn([(state) => state.foo], () => {
605599
executionId += 1;
606600
const id = executionId;
607601
executions.push({ id, type: 'effect' });

tests/typescript/effect-on.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
createStore,
3-
Unstable_EffectOn,
4-
unstable_effectOn,
5-
Action,
6-
action,
7-
} from 'easy-peasy';
1+
import { createStore, EffectOn, effectOn, Action, action } from 'easy-peasy';
82

93
interface Injections {
104
doSomething: () => Promise<void>;
@@ -14,7 +8,7 @@ interface TodosModel {
148
items: { id: number; text: string }[];
159
foo: string;
1610
setFoo: Action<TodosModel, string>;
17-
onStateChanged: Unstable_EffectOn<TodosModel, StoreModel, Injections>;
11+
onStateChanged: EffectOn<TodosModel, StoreModel, Injections>;
1812
}
1913

2014
interface StoreModel {
@@ -28,7 +22,7 @@ const todosModel: TodosModel = {
2822
setFoo: action((state, payload) => {
2923
state.foo = payload;
3024
}),
31-
onStateChanged: unstable_effectOn(
25+
onStateChanged: effectOn(
3226
[
3327
(state) => state.items,
3428
(state) => state.foo,

tests/typescript/external-type-defs.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import {
55
Computed,
66
thunk,
77
Thunk,
8-
unstable_effectOn,
9-
Unstable_EffectOn,
8+
effectOn,
9+
EffectOn,
1010
} from 'easy-peasy';
1111

12-
type MyModelEffectOn = Unstable_EffectOn<MyModel>;
12+
type MyModelEffectOn = EffectOn<MyModel>;
1313
type MyModelAction<TPayload = void> = Action<MyModel, TPayload>;
1414
type MyModelComputed<TResult> = Computed<MyModel, TResult>;
1515
type MyModelThunk<TPayload = undefined, TResult = any> = Thunk<
@@ -57,10 +57,7 @@ const myModel: MyModel = {
5757
return true;
5858
}),
5959

60-
myEffectOn: unstable_effectOn(
61-
[(state) => state.myState.value],
62-
(actions, change) => {
63-
// do something
64-
},
65-
),
60+
myEffectOn: effectOn([(state) => state.myState.value], (actions, change) => {
61+
// do something
62+
}),
6663
};

0 commit comments

Comments
 (0)