-
Notifications
You must be signed in to change notification settings - Fork 0
/
reduxular-element.ts
35 lines (32 loc) · 897 Bytes
/
reduxular-element.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import {
createObjectStore,
Store,
ReduxularListener
} from './reduxular';
import {
Reducer,
Action
} from 'redux';
/**
* Nearly the same type as Required<T> BUT allows the property value to be undefined.
* Example:
* type example = {
* prop?: number;
* };
*
* INVALID:
* const thing: Required<example> = {prop: undefined};
*
* VALID:
* const thing2: RequiredButAllowUndefined<example> = {prop: undefined};
*/
type RequiredButAllowUndefined<T> = {
[U in keyof Required<T>]: T[U];
};
export class ReduxularElement<State extends Object, A extends Action = any> extends HTMLElement {
readonly store: Store<State, A>;
constructor(initialState: RequiredButAllowUndefined<State>, listener: ReduxularListener<State>, reducer?: Reducer<State, A>) {
super();
this.store = createObjectStore(initialState, listener, this, reducer);
}
}