initialState

This commit is contained in:
Yanick Champoux 2023-03-02 11:42:33 -05:00
parent ad88599dd9
commit 7bb988aa54
2 changed files with 32 additions and 1 deletions

View File

@ -1 +1,17 @@
export default class Updux { } export default class Updux<T_Local_State = Record<any, any>> {
#local_initial: T_Local_State;
constructor(
config: Partial<{
initial: T_Local_State;
}>,
) {
// TODO test that we default to {}
this.#local_initial = config.initial ?? ({} as T_Local_State);
}
// TODO memoize?
get initial() {
return this.#local_initial;
}
}

15
src/initial.test.ts Normal file
View File

@ -0,0 +1,15 @@
import Updux from './Updux.js';
test('default', () => {
const { initial } = new Updux({});
expect(initial).toBeTypeOf('object');
expect(initial).toEqual({});
});
test('number', () => {
const { initial } = new Updux({ initial: 3 });
expect(initial).toBeTypeOf('number');
expect(initial).toEqual(3);
});