-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Labels
Description
I have just made a simple project to learn RESUB with React + Typescript.
Store
@AutoSubscribeStore
class PermissionsStore extends StoreBase {
private _permissions: string[] = [];
updatePermissions(permissions: string) {
this._permissions = this._permissions.concat(permissions);
this.trigger();
}
@autoSubscribe
getPermissions() {
return this._permissions;
}
}
export default new PermissionsStore();
Component
interface AppState {
permissions: string[],
}
export default class PermissionsComponent extends ComponentBase<any, AppState> {
getPermissions = async () => {
PermissionsStore.updatePermissions("loading")
}
render() {
return <React.Fragment>
{this.state.permissions?.length ? <h4>Loading</h4> : <h4>Not Loading</h4>}
<button onClick={this.getPermissions}>get Permissons</button>
</React.Fragment>;
}
protected _buildState(props: {}, initialBuild: boolean, incomingState: Readonly<AppState> | undefined): Partial<AppState> | undefined {
console.log('in build State')
return {permissions: PermissionsStore.getPermissions()}
}
}