ts-models
An implementation of models at TypeScript 2.0.
Features
- Virtual models - lightweight clone of the target instance without a deep clone of the attributes of the original model. The models have own state.
- Support a Flux application architecture (state: running, pending values, etc).
- Full Angular 2.0.0 two-way binding compatible.
- Basic methods supported, such as commit, rollback, getFieldValue, setFieldValue, toJSON, etc.
Dependencies
Installation
First you need to install the npm module:
npm install ts-models --save
Use case #1
Some main methods are present in the model:
- toJSON - returns the unmodifiable snapshot of original attributes.
- toAttributes - returns the modifiable snapshot of attributes with the changes if they exist (for binding at the Angular2 templates).
- commit - it must be called after the synchronization of client-server.
- getChanges - returns the unmodifiable snapshot of the changes of the original attributes.
;
; ;
Person: {{ modelToString(person.getChanges()) }} Virtual person 1:{{ modelToString(virtualPerson1.getChanges()) }} Virtual person 2:{{ modelToString(virtualPerson2.getChanges()) }} Submit changes
Use case #2
You can also use the @ViewField and @ViewSourceModel annotations.
; ;
Person: {{ modelToString(viewPerson.getChanges()) }} Submit changes
Publish
npm run deploy
License
Licensed under MIT.