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 | this.templateRef = templateRef;
|
12 | this.viewContainer = viewContainer;
|
13 | this.templateBindings = {};
|
14 | this.allAutorunOptions = [
|
15 | 'delay',
|
16 | 'scheduler',
|
17 | 'requiresObservable',
|
18 | 'name',
|
19 | 'onError'
|
20 | ];
|
21 | }
|
22 | ngOnInit() {
|
23 | this.view = this.viewContainer.createEmbeddedView(this.templateRef);
|
24 | if (this.dispose) {
|
25 | this.dispose();
|
26 | }
|
27 | if (this.shouldDetach()) {
|
28 | this.view.detach();
|
29 | }
|
30 | this.autoDetect(this.view);
|
31 |
|
32 | }
|
33 | shouldDetach() {
|
34 | return this.mobxAutorun && this.mobxAutorun.detach;
|
35 | }
|
36 | autoDetect(view) {
|
37 | const opts = this.getAutorunOptions();
|
38 | this.dispose = autorun(() => view.detectChanges(), opts);
|
39 | }
|
40 | getAutorunOptions() {
|
41 | return Object.keys(this.mobxAutorun || {}).reduce((opts, current) => {
|
42 | if (this.allAutorunOptions.includes(current)) {
|
43 | opts[current] = this.mobxAutorun[current];
|
44 | }
|
45 | return opts;
|
46 | }, {});
|
47 | }
|
48 | ngOnDestroy() {
|
49 | if (this.dispose) {
|
50 | this.dispose();
|
51 | }
|
52 | }
|
53 | }
|
54 | MobxAutorunDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: MobxAutorunDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
|
55 | MobxAutorunDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.1.5", type: MobxAutorunDirective, selector: "[mobxAutorun]", inputs: { mobxAutorun: "mobxAutorun" }, ngImport: i0 });
|
56 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: MobxAutorunDirective, decorators: [{
|
57 | type: Directive,
|
58 | args: [{ selector: '[mobxAutorun]' }]
|
59 | }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: i0.ViewContainerRef }]; }, propDecorators: { mobxAutorun: [{
|
60 | type: Input
|
61 | }] } });
|
62 |
|
63 | class MobxReactionDirective extends MobxAutorunDirective {
|
64 | constructor(templateRef, viewContainer) {
|
65 | super(templateRef, viewContainer);
|
66 | this.templateRef = templateRef;
|
67 | this.viewContainer = viewContainer;
|
68 | }
|
69 | autoDetect(view) {
|
70 | const opts = Object.assign({ fireImmediately: true }, this.mobxReactionOptions);
|
71 | this.dispose = reaction(this.mobxReaction, () => {
|
72 | view.detectChanges();
|
73 | }, opts);
|
74 | }
|
75 | }
|
76 | MobxReactionDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: MobxReactionDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
|
77 | MobxReactionDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.1.5", type: MobxReactionDirective, selector: "[mobxReaction]", inputs: { mobxReaction: "mobxReaction", mobxReactionOptions: "mobxReactionOptions" }, usesInheritance: true, ngImport: i0 });
|
78 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: MobxReactionDirective, decorators: [{
|
79 | type: Directive,
|
80 | args: [{ selector: '[mobxReaction]' }]
|
81 | }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: i0.ViewContainerRef }]; }, propDecorators: { mobxReaction: [{
|
82 | type: Input
|
83 | }], mobxReactionOptions: [{
|
84 | type: Input
|
85 | }] } });
|
86 |
|
87 | class RouterStore {
|
88 | constructor(router, activatedRoute) {
|
89 | this.router = router;
|
90 | this.activatedRoute = activatedRoute;
|
91 | this.url = '';
|
92 | this.routeSnapshot = null;
|
93 | makeAutoObservable(this);
|
94 | router.events
|
95 | .pipe(filter((event) => event instanceof NavigationEnd))
|
96 | .subscribe((e) => this.routeListener(e));
|
97 | }
|
98 | routeListener(event) {
|
99 | this.routeSnapshot = this.activatedRoute.snapshot;
|
100 | this.url = event.urlAfterRedirects;
|
101 | }
|
102 | }
|
103 | RouterStore.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: RouterStore, deps: [{ token: i1.Router }, { token: i1.ActivatedRoute }], target: i0.ɵɵFactoryTarget.Injectable });
|
104 | RouterStore.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: RouterStore, providedIn: 'root' });
|
105 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: RouterStore, decorators: [{
|
106 | type: Injectable,
|
107 | args: [{ providedIn: 'root' }]
|
108 | }], ctorParameters: function () { return [{ type: i1.Router }, { type: i1.ActivatedRoute }]; } });
|
109 |
|
110 | const DIRECTIVES = [MobxAutorunDirective, MobxReactionDirective];
|
111 | class MobxAngularModule {
|
112 | }
|
113 | MobxAngularModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: MobxAngularModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
114 | MobxAngularModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.5", ngImport: i0, type: MobxAngularModule, declarations: [MobxAutorunDirective, MobxReactionDirective], exports: [MobxAutorunDirective, MobxReactionDirective] });
|
115 | MobxAngularModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: MobxAngularModule });
|
116 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: MobxAngularModule, decorators: [{
|
117 | type: NgModule,
|
118 | args: [{
|
119 | declarations: DIRECTIVES,
|
120 | exports: DIRECTIVES
|
121 | }]
|
122 | }] });
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 | function actionInternal(...args) {
|
129 | return action$1(...args);
|
130 | }
|
131 | const action = Object.assign(actionInternal, action$1);
|
132 | function computedInternal(...args) {
|
133 | return computed$1(...args);
|
134 | }
|
135 | const computed = Object.assign(computedInternal, computed$1);
|
136 | function observableInternal(...args) {
|
137 | return observable$1(...args);
|
138 | }
|
139 | const observable = Object.assign(observableInternal, observable$1);
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 | export { MobxAngularModule, MobxAutorunDirective, MobxReactionDirective, RouterStore, action, actionInternal, computed, observable };
|
146 |
|