-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(store): add strong types to provider for stores with input and a…
…dd improved create options
- Loading branch information
1 parent
850a194
commit 17a5772
Showing
5 changed files
with
99 additions
and
25 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
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
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,63 @@ | ||
import { describe, expect, test, vi } from 'vitest'; | ||
import { createStoreContext, store } from '../src'; | ||
|
||
describe('should access and update the entire state', () => { | ||
const countStoreBuilder = store() | ||
.identify('countStore') | ||
.devtools() | ||
.input({ setting: false }) | ||
.state({ | ||
count: 2, | ||
}) | ||
.computed((store) => ({ | ||
doubled: () => store.count.get() * 2, | ||
})) | ||
.actions((store) => ({ | ||
increment() { | ||
store.count.set(store.count.get() + 1); | ||
}, | ||
decrement() { | ||
store.count.set(store.count.get() - 1); | ||
}, | ||
})) | ||
.effects((store) => ({ | ||
log: () => store.onChange(console.log), | ||
})); | ||
|
||
const countStore = countStoreBuilder.create(); | ||
|
||
const countStoreCtx = createStoreContext(countStoreBuilder); | ||
|
||
test('get', () => { | ||
const counterValues = countStore.count.get(); | ||
|
||
expect(counterValues).toBe(2); | ||
}); | ||
|
||
test('set', () => { | ||
countStore.count.set(10); | ||
|
||
expect(countStore.count.get()).toBe(10); | ||
}); | ||
|
||
test('assign', () => { | ||
// console.log('INSIDE ASSIGN NESTED OBJ: ', countStore); | ||
countStore.assign({ | ||
count: 30, | ||
}); | ||
|
||
expect(countStore.get()).toStrictEqual({ | ||
count: 30, | ||
}); | ||
}); | ||
|
||
test('input', () => { | ||
expect(countStore.setting).toBe(false); | ||
}); | ||
test('input with different instnes', () => { | ||
const countStore2 = countStoreBuilder.create({ setting: true }); | ||
|
||
expect(countStore.setting).toBe(false); | ||
expect(countStore2.setting).toBe(true); | ||
}); | ||
}); |