1 | import { autorun, reaction, makeAutoObservable, action as action$1, computed as computed$1, observable as observable$1 } from 'mobx';
|
2 | import * as i0 from '@angular/core';
|
3 | import { Directive, Input, Injectable, NgModule } from '@angular/core';
|
4 | import * as i1 from '@angular/router';
|
5 | import { NavigationEnd } from '@angular/router';
|
6 | import { filter } from 'rxjs/operators';
|
7 |
|
8 |
|
9 | class MobxAutorunDirective {
|
10 | constructor(templateRef, viewContainer) {
|
11 | Object.defineProperty(this, "templateRef", {
|
12 | enumerable: true,
|
13 | configurable: true,
|
14 | writable: true,
|
15 | value: templateRef
|
16 | });
|
17 | Object.defineProperty(this, "viewContainer", {
|
18 | enumerable: true,
|
19 | configurable: true,
|
20 | writable: true,
|
21 | value: viewContainer
|
22 | });
|
23 | Object.defineProperty(this, "templateBindings", {
|
24 | enumerable: true,
|
25 | configurable: true,
|
26 | writable: true,
|
27 | value: {}
|
28 | });
|
29 | Object.defineProperty(this, "dispose", {
|
30 | enumerable: true,
|
31 | configurable: true,
|
32 | writable: true,
|
33 | value: void 0
|
34 | });
|
35 | Object.defineProperty(this, "view", {
|
36 | enumerable: true,
|
37 | configurable: true,
|
38 | writable: true,
|
39 | value: void 0
|
40 | });
|
41 | Object.defineProperty(this, "allAutorunOptions", {
|
42 | enumerable: true,
|
43 | configurable: true,
|
44 | writable: true,
|
45 | value: [
|
46 | 'delay',
|
47 | 'scheduler',
|
48 | 'requiresObservable',
|
49 | 'name',
|
50 | 'onError'
|
51 | ]
|
52 | });
|
53 | Object.defineProperty(this, "mobxAutorun", {
|
54 | enumerable: true,
|
55 | configurable: true,
|
56 | writable: true,
|
57 | value: void 0
|
58 | });
|
59 | }
|
60 | ngOnInit() {
|
61 | this.view = this.viewContainer.createEmbeddedView(this.templateRef);
|
62 | if (this.dispose) {
|
63 | this.dispose();
|
64 | }
|
65 | if (this.shouldDetach()) {
|
66 | this.view.detach();
|
67 | }
|
68 | this.autoDetect(this.view);
|
69 |
|
70 | }
|
71 | shouldDetach() {
|
72 | return this.mobxAutorun && this.mobxAutorun.detach;
|
73 | }
|
74 | autoDetect(view) {
|
75 | const opts = this.getAutorunOptions();
|
76 | this.dispose = autorun(() => view.detectChanges(), opts);
|
77 | }
|
78 | getAutorunOptions() {
|
79 | return Object.keys(this.mobxAutorun || {}).reduce((opts, current) => {
|
80 | if (this.allAutorunOptions.includes(current)) {
|
81 | opts[current] = this.mobxAutorun[current];
|
82 | }
|
83 | return opts;
|
84 | }, {});
|
85 | }
|
86 | ngOnDestroy() {
|
87 | if (this.dispose) {
|
88 | this.dispose();
|
89 | }
|
90 | }
|
91 | }
|
92 | Object.defineProperty(MobxAutorunDirective, "\u0275fac", {
|
93 | enumerable: true,
|
94 | configurable: true,
|
95 | writable: true,
|
96 | value: i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MobxAutorunDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive })
|
97 | });
|
98 | Object.defineProperty(MobxAutorunDirective, "\u0275dir", {
|
99 | enumerable: true,
|
100 | configurable: true,
|
101 | writable: true,
|
102 | value: i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.0.0", type: MobxAutorunDirective, selector: "[mobxAutorun]", inputs: { mobxAutorun: "mobxAutorun" }, ngImport: i0 })
|
103 | });
|
104 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MobxAutorunDirective, decorators: [{
|
105 | type: Directive,
|
106 | args: [{ selector: '[mobxAutorun]' }]
|
107 | }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: i0.ViewContainerRef }]; }, propDecorators: { mobxAutorun: [{
|
108 | type: Input
|
109 | }] } });
|
110 |
|
111 | class MobxReactionDirective extends MobxAutorunDirective {
|
112 | constructor(templateRef, viewContainer) {
|
113 | super(templateRef, viewContainer);
|
114 | Object.defineProperty(this, "templateRef", {
|
115 | enumerable: true,
|
116 | configurable: true,
|
117 | writable: true,
|
118 | value: templateRef
|
119 | });
|
120 | Object.defineProperty(this, "viewContainer", {
|
121 | enumerable: true,
|
122 | configurable: true,
|
123 | writable: true,
|
124 | value: viewContainer
|
125 | });
|
126 | Object.defineProperty(this, "mobxReaction", {
|
127 | enumerable: true,
|
128 | configurable: true,
|
129 | writable: true,
|
130 | value: void 0
|
131 | });
|
132 | Object.defineProperty(this, "mobxReactionOptions", {
|
133 | enumerable: true,
|
134 | configurable: true,
|
135 | writable: true,
|
136 | value: void 0
|
137 | });
|
138 | }
|
139 | autoDetect(view) {
|
140 | const opts = Object.assign({ fireImmediately: true }, this.mobxReactionOptions);
|
141 | this.dispose = reaction(this.mobxReaction, () => {
|
142 | view.detectChanges();
|
143 | }, opts);
|
144 | }
|
145 | }
|
146 | Object.defineProperty(MobxReactionDirective, "\u0275fac", {
|
147 | enumerable: true,
|
148 | configurable: true,
|
149 | writable: true,
|
150 | value: i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MobxReactionDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive })
|
151 | });
|
152 | Object.defineProperty(MobxReactionDirective, "\u0275dir", {
|
153 | enumerable: true,
|
154 | configurable: true,
|
155 | writable: true,
|
156 | value: i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.0.0", type: MobxReactionDirective, selector: "[mobxReaction]", inputs: { mobxReaction: "mobxReaction", mobxReactionOptions: "mobxReactionOptions" }, usesInheritance: true, ngImport: i0 })
|
157 | });
|
158 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MobxReactionDirective, decorators: [{
|
159 | type: Directive,
|
160 | args: [{ selector: '[mobxReaction]' }]
|
161 | }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: i0.ViewContainerRef }]; }, propDecorators: { mobxReaction: [{
|
162 | type: Input
|
163 | }], mobxReactionOptions: [{
|
164 | type: Input
|
165 | }] } });
|
166 |
|
167 | class RouterStore {
|
168 | constructor(router, activatedRoute) {
|
169 | Object.defineProperty(this, "router", {
|
170 | enumerable: true,
|
171 | configurable: true,
|
172 | writable: true,
|
173 | value: router
|
174 | });
|
175 | Object.defineProperty(this, "activatedRoute", {
|
176 | enumerable: true,
|
177 | configurable: true,
|
178 | writable: true,
|
179 | value: activatedRoute
|
180 | });
|
181 | Object.defineProperty(this, "url", {
|
182 | enumerable: true,
|
183 | configurable: true,
|
184 | writable: true,
|
185 | value: ''
|
186 | });
|
187 | Object.defineProperty(this, "routeSnapshot", {
|
188 | enumerable: true,
|
189 | configurable: true,
|
190 | writable: true,
|
191 | value: null
|
192 | });
|
193 | makeAutoObservable(this);
|
194 | router.events
|
195 | .pipe(filter((event) => event instanceof NavigationEnd))
|
196 | .subscribe((e) => this.routeListener(e));
|
197 | }
|
198 | routeListener(event) {
|
199 | this.routeSnapshot = this.activatedRoute.snapshot;
|
200 | this.url = event.urlAfterRedirects;
|
201 | }
|
202 | }
|
203 | Object.defineProperty(RouterStore, "\u0275fac", {
|
204 | enumerable: true,
|
205 | configurable: true,
|
206 | writable: true,
|
207 | value: i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: RouterStore, deps: [{ token: i1.Router }, { token: i1.ActivatedRoute }], target: i0.ɵɵFactoryTarget.Injectable })
|
208 | });
|
209 | Object.defineProperty(RouterStore, "\u0275prov", {
|
210 | enumerable: true,
|
211 | configurable: true,
|
212 | writable: true,
|
213 | value: i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: RouterStore, providedIn: 'root' })
|
214 | });
|
215 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: RouterStore, decorators: [{
|
216 | type: Injectable,
|
217 | args: [{ providedIn: 'root' }]
|
218 | }], ctorParameters: function () { return [{ type: i1.Router }, { type: i1.ActivatedRoute }]; } });
|
219 |
|
220 | const DIRECTIVES = [MobxAutorunDirective, MobxReactionDirective];
|
221 | class MobxAngularModule {
|
222 | }
|
223 | Object.defineProperty(MobxAngularModule, "\u0275fac", {
|
224 | enumerable: true,
|
225 | configurable: true,
|
226 | writable: true,
|
227 | value: i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MobxAngularModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule })
|
228 | });
|
229 | Object.defineProperty(MobxAngularModule, "\u0275mod", {
|
230 | enumerable: true,
|
231 | configurable: true,
|
232 | writable: true,
|
233 | value: i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MobxAngularModule, declarations: [MobxAutorunDirective, MobxReactionDirective], exports: [MobxAutorunDirective, MobxReactionDirective] })
|
234 | });
|
235 | Object.defineProperty(MobxAngularModule, "\u0275inj", {
|
236 | enumerable: true,
|
237 | configurable: true,
|
238 | writable: true,
|
239 | value: i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MobxAngularModule })
|
240 | });
|
241 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MobxAngularModule, decorators: [{
|
242 | type: NgModule,
|
243 | args: [{
|
244 | declarations: DIRECTIVES,
|
245 | exports: DIRECTIVES
|
246 | }]
|
247 | }] });
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 | function actionInternal(...args) {
|
254 | return action$1(...args);
|
255 | }
|
256 | const action = Object.assign(actionInternal, action$1);
|
257 | function computedInternal(...args) {
|
258 | return computed$1(...args);
|
259 | }
|
260 | const computed = Object.assign(computedInternal, computed$1);
|
261 | function observableInternal(...args) {
|
262 | return observable$1(...args);
|
263 | }
|
264 | const observable = Object.assign(observableInternal, observable$1);
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 | export { MobxAngularModule, MobxAutorunDirective, MobxReactionDirective, RouterStore, action, actionInternal, computed, observable };
|