1 | "use strict";
|
2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7 | };
|
8 | var __metadata = (this && this.__metadata) || function (k, v) {
|
9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
10 | };
|
11 | var __param = (this && this.__param) || function (paramIndex, decorator) {
|
12 | return function (target, key) { decorator(target, key, paramIndex); }
|
13 | };
|
14 | var core_1 = require('angular2/core');
|
15 | exports.WEBPACK_HMR = new core_1.OpaqueToken('$$AppState');
|
16 | var WebpackState = (function () {
|
17 | function WebpackState(state) {
|
18 | this._state = {};
|
19 | this._noop = Function.prototype;
|
20 | this._states = [];
|
21 | if (state) {
|
22 | console.log('WebpackState initial data', state);
|
23 | }
|
24 | this._state = state || this._state;
|
25 | }
|
26 | WebpackState.prototype.set = function (prop, value) {
|
27 | this._state[prop] = value;
|
28 | return this._state[prop];
|
29 | };
|
30 | WebpackState.prototype.get = function (prop) {
|
31 | return this._state[prop];
|
32 | };
|
33 | WebpackState.prototype.select = function (name, getState) {
|
34 | this._states.push({ name: name, getState: getState });
|
35 | return this.set(name, this.get(name) || getState());
|
36 | };
|
37 | WebpackState.prototype.dispose = function () {
|
38 | this._states = [];
|
39 | };
|
40 | WebpackState.prototype.getState = function () {
|
41 | var initialState = Object.assign({}, this._state);
|
42 | return this._states
|
43 | .reduce(function (memo, item) {
|
44 | memo[item.name] = item.getState();
|
45 | return memo;
|
46 | }, initialState);
|
47 | };
|
48 | WebpackState.prototype.toJSON = function () {
|
49 | return this.getState();
|
50 | };
|
51 | WebpackState = __decorate([
|
52 | __param(0, core_1.Optional()),
|
53 | __param(0, core_1.Inject(exports.WEBPACK_HMR)),
|
54 | __metadata('design:paramtypes', [Object])
|
55 | ], WebpackState);
|
56 | return WebpackState;
|
57 | }());
|
58 | exports.WebpackState = WebpackState;
|
59 | function provideInitialState(initialState) {
|
60 | if (initialState === void 0) { initialState = {}; }
|
61 | return [
|
62 | new core_1.Provider(exports.WEBPACK_HMR, { useValue: initialState }),
|
63 | new core_1.Provider(WebpackState, { useClass: WebpackState })
|
64 | ];
|
65 | }
|
66 | exports.provideInitialState = provideInitialState;
|
67 |
|
\ | No newline at end of file |