UNPKG

8.19 kBSource Map (JSON)View Raw
1{"version":3,"file":"mobx-angular.js","sources":["../../../projects/mobx-angular/src/lib/mobx-autorun.directive.ts","../../../projects/mobx-angular/src/lib/mobx-reaction.directive.ts","../../../projects/mobx-angular/src/lib/router-store.service.ts","../../../projects/mobx-angular/src/lib/mobx-angular.module.ts","../../../projects/mobx-angular/src/public-api.ts","../../../projects/mobx-angular/src/mobx-angular.ts"],"sourcesContent":["import {\n Directive,\n ViewContainerRef,\n TemplateRef,\n OnInit,\n OnDestroy,\n Input,\n EmbeddedViewRef\n} from '@angular/core';\nimport { autorun, IAutorunOptions } from 'mobx';\n// import { mobxAngularDebug } from '../utils/mobx-angular-debug';\n\n@Directive({ selector: '[mobxAutorun]' })\nexport class MobxAutorunDirective implements OnInit, OnDestroy {\n protected templateBindings = {};\n protected dispose: any;\n protected view: EmbeddedViewRef<any>;\n private readonly allAutorunOptions: Array<keyof IAutorunOptions> = [\n 'delay',\n 'scheduler',\n 'requiresObservable',\n 'name',\n 'onError'\n ];\n @Input() mobxAutorun;\n\n constructor(\n protected templateRef: TemplateRef<any>,\n protected viewContainer: ViewContainerRef\n ) {}\n\n ngOnInit() {\n this.view = this.viewContainer.createEmbeddedView(this.templateRef);\n\n if (this.dispose) {\n this.dispose();\n }\n\n if (this.shouldDetach()) {\n this.view.detach();\n }\n this.autoDetect(this.view);\n // mobxAngularDebug(this.view, this.dispose);\n }\n\n shouldDetach() {\n return this.mobxAutorun && this.mobxAutorun.detach;\n }\n\n autoDetect(view: EmbeddedViewRef<any>) {\n const opts: IAutorunOptions = this.getAutorunOptions();\n\n this.dispose = autorun(() => view.detectChanges(), opts);\n }\n\n getAutorunOptions(): IAutorunOptions {\n return Object.keys(this.mobxAutorun || {}).reduce((opts, current) => {\n if (this.allAutorunOptions.includes(current as keyof IAutorunOptions)) {\n opts[current] = this.mobxAutorun[current];\n }\n return opts;\n }, {});\n }\n\n ngOnDestroy() {\n if (this.dispose) {\n this.dispose();\n }\n }\n}\n","import { Directive, ViewContainerRef, TemplateRef, Input } from '@angular/core';\nimport { IReactionOptions, reaction } from 'mobx';\nimport { MobxAutorunDirective } from './mobx-autorun.directive';\n\n@Directive({ selector: '[mobxReaction]' })\nexport class MobxReactionDirective extends MobxAutorunDirective {\n @Input() mobxReaction;\n @Input() mobxReactionOptions: IReactionOptions;\n\n constructor(\n protected templateRef: TemplateRef<any>,\n protected viewContainer: ViewContainerRef\n ) {\n super(templateRef, viewContainer);\n }\n\n autoDetect(view) {\n const opts: IReactionOptions = Object.assign({ fireImmediately: true }, this.mobxReactionOptions);\n\n this.dispose = reaction(\n this.mobxReaction,\n () => {\n view.detectChanges();\n },\n opts\n );\n }\n}\n","import { Injectable } from '@angular/core';\nimport { makeAutoObservable } from 'mobx';\nimport {\n ActivatedRoute,\n ActivatedRouteSnapshot,\n NavigationEnd,\n Router\n} from '@angular/router';\nimport { filter } from 'rxjs/operators';\n\n@Injectable({ providedIn: 'root' })\nexport class RouterStore {\n url = '';\n routeSnapshot: ActivatedRouteSnapshot = null;\n\n constructor(private router: Router, private activatedRoute: ActivatedRoute) {\n makeAutoObservable(this);\n\n router.events\n .pipe(filter((event) => event instanceof NavigationEnd))\n .subscribe((e: NavigationEnd) => this.routeListener(e));\n }\n\n private routeListener(event: NavigationEnd) {\n this.routeSnapshot = this.activatedRoute.snapshot;\n this.url = event.urlAfterRedirects;\n }\n}\n","import { NgModule } from '@angular/core';\nimport { MobxAutorunDirective } from './mobx-autorun.directive';\nimport { MobxReactionDirective } from './mobx-reaction.directive';\n\nconst DIRECTIVES = [MobxAutorunDirective, MobxReactionDirective];\n@NgModule({\n declarations: DIRECTIVES,\n exports: DIRECTIVES\n})\nexport class MobxAngularModule {}\n","/*\n * Public API Surface of mobx-angular\n */\n\nimport { action as mobxAction } from 'mobx';\nimport { computed as mobxComputed } from 'mobx';\nimport { observable as mobxObservable } from 'mobx';\n\nexport * from './lib/mobx-autorun.directive';\nexport * from './lib/mobx-reaction.directive';\nexport * from './lib/router-store.service';\nexport * from './lib/mobx-angular.module';\n\n// Re-export mobx operators to be able to use inside components with AOT:\nexport function actionInternal(...args) {\n return (mobxAction as any)(...args);\n}\nexport const action: typeof mobxAction = Object.assign(\n actionInternal,\n mobxAction\n) as any;\n\nfunction computedInternal(...args) {\n return (mobxComputed as any)(...args);\n}\nexport const computed: typeof mobxComputed = Object.assign(\n computedInternal,\n mobxComputed\n) as any;\n\nfunction observableInternal(...args) {\n return (mobxObservable as any)(...args);\n}\n\nexport const observable: typeof mobxObservable = Object.assign(\n observableInternal,\n mobxObservable\n) as any;\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["mobxAction","mobxComputed","mobxObservable"],"mappings":";;;;;AAUA;MAGa,oBAAoB;IAa/B,YACY,WAA6B,EAC7B,aAA+B;QAD/B,gBAAW,GAAX,WAAW,CAAkB;QAC7B,kBAAa,GAAb,aAAa,CAAkB;QAdjC,qBAAgB,GAAG,EAAE,CAAC;QAGf,sBAAiB,GAAiC;YACjE,OAAO;YACP,WAAW;YACX,oBAAoB;YACpB,MAAM;YACN,SAAS;SACV,CAAC;KAME;IAEJ,QAAQ;QACN,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAEpE,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,IAAI,CAAC,OAAO,EAAE,CAAC;SAChB;QAED,IAAI,IAAI,CAAC,YAAY,EAAE,EAAE;YACvB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;SACpB;QACD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;KAE5B;IAED,YAAY;QACV,OAAO,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;KACpD;IAED,UAAU,CAAC,IAA0B;QACnC,MAAM,IAAI,GAAoB,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAEvD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