Skip to content

Commit

Permalink
Add Prettier (Close #108)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubk committed Jan 5, 2020
1 parent 82eaa7f commit 1f7e533
Show file tree
Hide file tree
Showing 8 changed files with 1,340 additions and 145 deletions.
8 changes: 6 additions & 2 deletions lib/directives/mobx-autorun-sync.directive.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Directive, ViewContainerRef, TemplateRef } from '@angular/core';
import { autorun } from 'mobx';
import {MobxAutorunDirective} from './mobx-autorun.directive';
import { MobxAutorunDirective } from './mobx-autorun.directive';

@Directive({ selector: '[mobxAutorunSync]' })
export class MobxAutorunSyncDirective extends MobxAutorunDirective {
constructor(
protected templateRef: TemplateRef<any>,
protected viewContainer: ViewContainerRef) {super(templateRef, viewContainer); }
protected viewContainer: ViewContainerRef
) {
super(templateRef, viewContainer);
}

autoDetect(view) {
// prettier-ignore
console.warn('mobxAutorunSync is deprecated, please use mobxAutorun instead - it\'s doing exactly the same thing');

this.dispose = autorun(() => {
Expand Down
18 changes: 12 additions & 6 deletions lib/directives/mobx-autorun.directive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Directive, ViewContainerRef, TemplateRef, OnInit, OnDestroy, Input, EmbeddedViewRef } from '@angular/core';
import {
Directive,
ViewContainerRef,
TemplateRef,
OnInit,
OnDestroy,
Input,
EmbeddedViewRef
} from '@angular/core';
import { autorun } from 'mobx';
// import { mobxAngularDebug } from '../utils/mobx-angular-debug';

Expand All @@ -11,8 +19,8 @@ export class MobxAutorunDirective implements OnInit, OnDestroy {

constructor(
protected templateRef: TemplateRef<any>,
protected viewContainer: ViewContainerRef) {
}
protected viewContainer: ViewContainerRef
) {}

ngOnInit() {
this.view = this.viewContainer.createEmbeddedView(this.templateRef);
Expand All @@ -31,9 +39,7 @@ export class MobxAutorunDirective implements OnInit, OnDestroy {
}

autoDetect(view: EmbeddedViewRef<any>) {
this.dispose = autorun(
() => view.detectChanges(),
);
this.dispose = autorun(() => view.detectChanges());
}

ngOnDestroy() {
Expand Down
17 changes: 12 additions & 5 deletions lib/directives/mobx-reaction.directive.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import { Directive, ViewContainerRef, TemplateRef, Input } from '@angular/core';
import { reaction } from 'mobx';
import {MobxAutorunDirective} from './mobx-autorun.directive';
import { MobxAutorunDirective } from './mobx-autorun.directive';

@Directive({ selector: '[mobxReaction]' })
export class MobxReactionDirective extends MobxAutorunDirective {
@Input() mobxReaction;

constructor(
protected templateRef: TemplateRef<any>,
protected viewContainer: ViewContainerRef) {super(templateRef, viewContainer); }
protected viewContainer: ViewContainerRef
) {
super(templateRef, viewContainer);
}

autoDetect(view) {
this.dispose = reaction(this.mobxReaction, () => {
view['detectChanges']();
}, { fireImmediately: true });
this.dispose = reaction(
this.mobxReaction,
() => {
view['detectChanges']();
},
{ fireImmediately: true }
);
}
}
31 changes: 15 additions & 16 deletions lib/mobx-angular.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import { NgModule } from '@angular/core';
import {MobxAutorunDirective} from './directives/mobx-autorun.directive';
import {MobxAutorunSyncDirective} from './directives/mobx-autorun-sync.directive';
import {MobxReactionDirective} from './directives/mobx-reaction.directive';
import {action as mobxAction} from 'mobx';
import {computed as mobxComputed} from 'mobx';
import {observable as mobxObservable} from 'mobx';
import { MobxAutorunDirective } from './directives/mobx-autorun.directive';
import { MobxAutorunSyncDirective } from './directives/mobx-autorun-sync.directive';
import { MobxReactionDirective } from './directives/mobx-reaction.directive';
import { action as mobxAction } from 'mobx';
import { computed as mobxComputed } from 'mobx';
import { observable as mobxObservable } from 'mobx';

export {
MobxAutorunDirective,
MobxAutorunSyncDirective,
MobxReactionDirective
}
};

const DIRECTIVES = [MobxAutorunDirective, MobxAutorunSyncDirective, MobxReactionDirective];
const DIRECTIVES = [
MobxAutorunDirective,
MobxAutorunSyncDirective,
MobxReactionDirective
];
@NgModule({
declarations: [
...DIRECTIVES
],
exports: [
...DIRECTIVES
],
declarations: [...DIRECTIVES],
exports: [...DIRECTIVES],
imports: [],
providers: []
})
export class MobxAngularModule {
}
export class MobxAngularModule {}

export function action(...args) {
return (mobxAction as any)(...args);
Expand Down
Loading

0 comments on commit 1f7e533

Please sign in to comment.