Closed sachinrajesh closed 2 years ago
@sachinrajesh Could you drop a code snip showing how you're trying to use the store?
// STORE AND REDUCER import { ActionCreatorsObject, ActionsUnion, createAction, ReducerRegistryInstance, StateManager, UiFramework } from "@bentley/ui-framework"; import { Task } from "../interfaces/Task";
interface ITasksState { bimTaskElements: Task[] }
export class TasksStateManager { public static packageStateManagerLoaded = false;
private static _initialState: ITasksState = { bimTaskElements: [], };
private static _reducerName = "tasksState";
public static SET_BIM_TASK_ELEMENTS = TasksStateManager.createActionName("SET_BIM_TASK_ELEMENTS");
private static _packageActions: ActionCreatorsObject = { setDialogVisible: (packageUiVisible: boolean) => createAction(TasksStateManager.SET_BIM_TASK_ELEMENTS, packageUiVisible), };
private static createActionName(name: string) {
return ${TasksStateManager._reducerName}:${name}
.toLowerCase();
}
public static reducer(
state: ITasksState = TasksStateManager._initialState,
action: any,
): ITasksState {
type PackageActionsUnion = ActionsUnion
switch (packageActionsParam.type) {
case TasksStateManager.SET_BIM_TASK_ELEMENTS:
return { ...state, bimTaskElements: action.payload };
default:
return state;
}
}
public static initialize() { ReducerRegistryInstance.registerReducer( TasksStateManager._reducerName, TasksStateManager.reducer, ); TasksStateManager.packageStateManagerLoaded = true; }
public static get bimTaskElements(): Task[] { if (StateManager.isInitialized()) { return StateManager.store.getState().tasksState.bimTaskElements; } else { return []; } }
public static set bimTaskElements(value: Task[]) { UiFramework.dispatchActionToStore(TasksStateManager.SET_BIM_TASK_ELEMENTS, value, true); } }
// SETTING bimTaskElements TasksStateManager.bimTaskElements = taskElementsFromApi;
// GETTING bimTaskElements const taskElementsFromStore = TasksStateManager.bimTaskElements;
The above mentioned is a working snippet. Previously I had trouble implementing this only because the packages were imported from "@itwin/appui-react" instead of "@bentley/ui-framework".
The above mentioned is a working snippet. Previously I had trouble implementing this only because the packages were imported from "@itwin/appui-react" instead of "@bentley/ui-framework".
I'm confused -- the above snippet works in 3.x or it worked in 2.x and doesn't work now? (The name of the package changed from @bentley/ui-framework to @itwin/appui-react in 3.0.)
My problems went away now since I started using packages from @bentley/ui-framework. I just wanted to point out that the package @itwin/appui-react doesn't work as expected.
Unable to store data using "ReducerRegistryInstance", "StateManager" from "@itwin/appui-react". However the same codes will run as expected using packages from "@bentley/ui-framework".
⚠ Do not edit this section. It is required for imodeljs.github.io ➟ GitHub issue linking