initialState
This commit is contained in:
parent
ad88599dd9
commit
7bb988aa54
18
src/Updux.ts
18
src/Updux.ts
@ -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
15
src/initial.test.ts
Normal 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);
|
||||
});
|
Loading…
Reference in New Issue
Block a user