forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStore.ts
42 lines (33 loc) · 1.33 KB
/
Store.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
36
37
38
39
40
41
42
import { ComponentProvider } from 'react-native';
import { IWrappedComponent } from './ComponentWrapper';
export class Store {
private componentsByName: Record<string, ComponentProvider> = {};
private propsById: Record<string, any> = {};
private componentsInstancesById: Record<string, IWrappedComponent> = {};
setPropsForId(componentId: string, props: any) {
this.propsById[componentId] = props;
const component = this.componentsInstancesById[componentId];
if (component) {
this.componentsInstancesById[componentId].setProps(props);
}
}
getPropsForId(componentId: string) {
return this.propsById[componentId] || {};
}
clearComponent(componentId: string) {
delete this.propsById[componentId];
delete this.componentsInstancesById[componentId];
}
setComponentClassForName(componentName: string | number, ComponentClass: ComponentProvider) {
this.componentsByName[componentName.toString()] = ComponentClass;
}
getComponentClassForName(componentName: string | number): ComponentProvider | undefined {
return this.componentsByName[componentName.toString()];
}
setComponentInstance(id: string, component: IWrappedComponent): void {
this.componentsInstancesById[id] = component;
}
getComponentInstance(id: string): IWrappedComponent {
return this.componentsInstancesById[id];
}
}