1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('mobx')) :
|
3 | typeof define === 'function' && define.amd ? define(['exports', '@angular/core', 'mobx'], factory) :
|
4 | (factory((global['mobx-angular'] = global['mobx-angular'] || {}),global._angular_core,global.mobx));
|
5 | }(this, (function (exports,_angular_core,mobx) { 'use strict';
|
6 |
|
7 |
|
8 | var MobxAutorunDirective = (function () {
|
9 | function MobxAutorunDirective(templateRef, viewContainer) {
|
10 | this.templateRef = templateRef;
|
11 | this.viewContainer = viewContainer;
|
12 | this.templateBindings = {};
|
13 | }
|
14 | MobxAutorunDirective.prototype.ngOnInit = function () {
|
15 | this.view = this.viewContainer.createEmbeddedView(this.templateRef);
|
16 | if (this.dispose)
|
17 | this.dispose();
|
18 | if (this.shouldDetach()) {
|
19 | this.view.detach();
|
20 | }
|
21 | this.autoDetect(this.view);
|
22 |
|
23 | };
|
24 | MobxAutorunDirective.prototype.shouldDetach = function () {
|
25 | return this.mobxAutorun && this.mobxAutorun.detach;
|
26 | };
|
27 | MobxAutorunDirective.prototype.autoDetect = function (view) {
|
28 | var autorunName = view._view.component
|
29 | ? view._view.component.constructor.name + ".detectChanges()"
|
30 | : view._view.parentView.context.constructor.name + ".detectChanges()";
|
31 | this.dispose = mobx.autorun(function () { return view['detectChanges'](); }, { name: autorunName });
|
32 | };
|
33 | MobxAutorunDirective.prototype.ngOnDestroy = function () {
|
34 | if (this.dispose)
|
35 | this.dispose();
|
36 | };
|
37 | MobxAutorunDirective.decorators = [
|
38 | { type: _angular_core.Directive, args: [{ selector: '[mobxAutorun]' },] },
|
39 | ];
|
40 |
|
41 | MobxAutorunDirective.ctorParameters = function () { return [
|
42 | { type: _angular_core.TemplateRef, },
|
43 | { type: _angular_core.ViewContainerRef, },
|
44 | ]; };
|
45 | MobxAutorunDirective.propDecorators = {
|
46 | "mobxAutorun": [{ type: _angular_core.Input },],
|
47 | };
|
48 | return MobxAutorunDirective;
|
49 | }());
|
50 |
|
51 | var __extends = (undefined && undefined.__extends) || (function () {
|
52 | var extendStatics = Object.setPrototypeOf ||
|
53 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
54 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
55 | return function (d, b) {
|
56 | extendStatics(d, b);
|
57 | function __() { this.constructor = d; }
|
58 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
59 | };
|
60 | })();
|
61 | var MobxAutorunSyncDirective = (function (_super) {
|
62 | __extends(MobxAutorunSyncDirective, _super);
|
63 | function MobxAutorunSyncDirective(templateRef, viewContainer) {
|
64 | var _this = _super.call(this, templateRef, viewContainer) || this;
|
65 | _this.templateRef = templateRef;
|
66 | _this.viewContainer = viewContainer;
|
67 | return _this;
|
68 | }
|
69 | MobxAutorunSyncDirective.prototype.autoDetect = function (view) {
|
70 | console.warn('mobxAutorunSync is deprecated, please use mobxAutorun instead - it\'s doing exactly the same thing');
|
71 | this.dispose = mobx.autorun(function () {
|
72 | view['detectChanges']();
|
73 | });
|
74 | };
|
75 | MobxAutorunSyncDirective.decorators = [
|
76 | { type: _angular_core.Directive, args: [{ selector: '[mobxAutorunSync]' },] },
|
77 | ];
|
78 |
|
79 | MobxAutorunSyncDirective.ctorParameters = function () { return [
|
80 | { type: _angular_core.TemplateRef, },
|
81 | { type: _angular_core.ViewContainerRef, },
|
82 | ]; };
|
83 | return MobxAutorunSyncDirective;
|
84 | }(MobxAutorunDirective));
|
85 |
|
86 | var __extends$1 = (undefined && undefined.__extends) || (function () {
|
87 | var extendStatics = Object.setPrototypeOf ||
|
88 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
89 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
90 | return function (d, b) {
|
91 | extendStatics(d, b);
|
92 | function __() { this.constructor = d; }
|
93 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
94 | };
|
95 | })();
|
96 | var MobxReactionDirective = (function (_super) {
|
97 | __extends$1(MobxReactionDirective, _super);
|
98 | function MobxReactionDirective(templateRef, viewContainer) {
|
99 | var _this = _super.call(this, templateRef, viewContainer) || this;
|
100 | _this.templateRef = templateRef;
|
101 | _this.viewContainer = viewContainer;
|
102 | return _this;
|
103 | }
|
104 | MobxReactionDirective.prototype.autoDetect = function (view) {
|
105 | this.dispose = mobx.reaction(this.mobxReaction, function () {
|
106 | view['detectChanges']();
|
107 | }, { fireImmediately: true });
|
108 | };
|
109 | MobxReactionDirective.decorators = [
|
110 | { type: _angular_core.Directive, args: [{ selector: '[mobxReaction]' },] },
|
111 | ];
|
112 |
|
113 | MobxReactionDirective.ctorParameters = function () { return [
|
114 | { type: _angular_core.TemplateRef, },
|
115 | { type: _angular_core.ViewContainerRef, },
|
116 | ]; };
|
117 | MobxReactionDirective.propDecorators = {
|
118 | "mobxReaction": [{ type: _angular_core.Input },],
|
119 | };
|
120 | return MobxReactionDirective;
|
121 | }(MobxAutorunDirective));
|
122 |
|
123 | var DIRECTIVES = [MobxAutorunDirective, MobxAutorunSyncDirective, MobxReactionDirective];
|
124 | var MobxAngularModule = (function () {
|
125 | function MobxAngularModule() {
|
126 | }
|
127 | MobxAngularModule.decorators = [
|
128 | { type: _angular_core.NgModule, args: [{
|
129 | declarations: DIRECTIVES.slice(),
|
130 | exports: DIRECTIVES.slice(),
|
131 | imports: [],
|
132 | providers: []
|
133 | },] },
|
134 | ];
|
135 |
|
136 | MobxAngularModule.ctorParameters = function () { return []; };
|
137 | return MobxAngularModule;
|
138 | }());
|
139 | function action$1() {
|
140 | var args = [];
|
141 | for (var _i = 0; _i < arguments.length; _i++) {
|
142 | args[_i] = arguments[_i];
|
143 | }
|
144 | return mobx.action.apply(void 0, args);
|
145 | }
|
146 | function computed$1() {
|
147 | var args = [];
|
148 | for (var _i = 0; _i < arguments.length; _i++) {
|
149 | args[_i] = arguments[_i];
|
150 | }
|
151 | return mobx.computed.apply(void 0, args);
|
152 | }
|
153 | function observable$1() {
|
154 | var args = [];
|
155 | for (var _i = 0; _i < arguments.length; _i++) {
|
156 | args[_i] = arguments[_i];
|
157 | }
|
158 | return mobx.observable.apply(void 0, args);
|
159 | }
|
160 |
|
161 | exports.MobxAutorunDirective = MobxAutorunDirective;
|
162 | exports.MobxAutorunSyncDirective = MobxAutorunSyncDirective;
|
163 | exports.MobxReactionDirective = MobxReactionDirective;
|
164 | exports.MobxAngularModule = MobxAngularModule;
|
165 | exports.action = action$1;
|
166 | exports.computed = computed$1;
|
167 | exports.observable = observable$1;
|
168 |
|
169 | Object.defineProperty(exports, '__esModule', { value: true });
|
170 |
|
171 | })));
|