mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-23 19:00:13 +01:00
Initial commit.
This commit is contained in:
commit
6558ee2fc4
92 changed files with 3193 additions and 0 deletions
39
src/app/app.service.ts
Normal file
39
src/app/app.service.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import {Injectable} from 'angular2/core';
|
||||
import {HmrState} from 'angular2-hmr';
|
||||
|
||||
@Injectable()
|
||||
export class AppState {
|
||||
// HmrState uis used by HMR to track the any state during reloading
|
||||
@HmrState() _state = {};
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
// already return a clone of the current state
|
||||
get state() {
|
||||
return this._state = this._clone(this._state);
|
||||
}
|
||||
// never allow mutation
|
||||
set state(value) {
|
||||
throw new Error('do not mutate the `.state` directly');
|
||||
}
|
||||
|
||||
|
||||
get(prop?: any) {
|
||||
// use our state getter for the clone
|
||||
const state = this.state;
|
||||
return state[prop] || state;
|
||||
}
|
||||
|
||||
set(prop: string, value: any) {
|
||||
// internally mutate our state
|
||||
return this._state[prop] = value;
|
||||
}
|
||||
|
||||
|
||||
_clone(object) {
|
||||
// simple object clone
|
||||
return JSON.parse(JSON.stringify( object ));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue