-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(empty): add operator * Update src/empty/readme.md Co-authored-by: Sergey Sova <[email protected]> * Update src/empty/index.ts Co-authored-by: Sergey Sova <[email protected]> * Update src/empty/index.ts * chore(empty): fixes after review Co-authored-by: Sergey Sova <[email protected]>
- Loading branch information
1 parent
856de14
commit e2a4ed6
Showing
5 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { allSettled, createEvent, createStore, fork } from 'effector'; | ||
import { empty } from './index'; | ||
|
||
test('boolean', async () => { | ||
const makeFalse = createEvent(); | ||
const $a = createStore<boolean | null>(null).on(makeFalse, (_) => false); | ||
const $result = empty($a); | ||
|
||
const scope = fork(); | ||
|
||
expect(scope.getState($result)).toBe(true); | ||
|
||
await allSettled(makeFalse, { scope }); | ||
expect(scope.getState($result)).toBe(false); | ||
}); | ||
|
||
test('numbers', async () => { | ||
const increment = createEvent(); | ||
const $a = createStore<number | null>(null).on(increment, (a) => (a ?? -1) + 1); | ||
const $result = empty($a); | ||
|
||
const scope = fork(); | ||
|
||
expect(scope.getState($result)).toBe(true); | ||
|
||
await allSettled(increment, { scope }); | ||
expect(scope.getState($result)).toBe(false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { createEvent, createStore } from 'effector'; | ||
import { empty } from './index'; | ||
|
||
test('boolean', () => { | ||
const makeFalse = createEvent(); | ||
const $a = createStore<boolean | null>(null).on(makeFalse, (_) => false); | ||
const $result = empty($a); | ||
|
||
expect($result.getState()).toBe(true); | ||
|
||
makeFalse(); | ||
expect($result.getState()).toBe(false); | ||
}); | ||
|
||
test('numbers', () => { | ||
const increment = createEvent(); | ||
const $a = createStore<number | null>(null).on(increment, (a) => (a ?? -1) + 1); | ||
const $result = empty($a); | ||
|
||
expect($result.getState()).toBe(true); | ||
|
||
increment(); | ||
expect($result.getState()).toBe(false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Store } from 'effector'; | ||
|
||
export function empty<A>(a: Store<A | null>): Store<boolean> { | ||
return a.map((value) => value === null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# empty (experimental) | ||
|
||
> Since 1.10.0 |