ui5-state
is a simple ui5 state management library which aims to utilize TypeScript in order to provide typed and safe access to your JSONModel
data.
- fully type-safe read access
- streamlined write access
DeepReadonly
reference exposure
npm install ui5-state
- Enable dependency transpilation (relevant when
serve
ing the app)
- name: ui5-tooling-transpile-middleware
afterMiddleware: compression
configuration:
transpileDependencies: true
- setup ui5-workspace.yaml (relevant when
serve
ing the app)
specVersion: workspace/1.0
metadata:
name: default
dependencyManagement:
resolutions:
- path: ./node_modules/ui5-state
- Setup
tsconfig.json
as follows:
{
"compilerOptions": {
"paths": {
"ui5-state/*": [
"./node_modules/ui5-state/src/com/github/dfenerski/ui5_state/*"
],
}
}
}
import { StateService } from 'ui5-state/State.service';
import type { App } from './model/App';
import type { AppViewType } from './types/AppViewType';
export const APP_MODEL = 'app';
export class AppStateService extends StateService<App> {
public setCurrentView(view: AppViewType) {
return this._model.setProperty('/currentView', view);
}
}
// Component.ts
this.appModel = new AppStateService({
componentRef: this,
data: new App(),
registrationToken: APP_MODEL,
});
// SomeController.ts
/**
* @namespace com.someorg.myapp
*/
export default class SomeController {
public onInit(){
const component = getComponent();
this.appModel = component.appModel.
}
public handleCurrentViewPromptRequest(){
alert(this.appModel.state.currentView);
}
}