This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createStore(reducer, initialState) { | |
var currentReducer = reducer; | |
var currentState = initialState; | |
var listener = () => {}; | |
return { | |
getState() { | |
return currentState; | |
}, | |
dispatch(action) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function counter(state = 0, action) { | |
switch (action.type) { | |
case 'INCREMENT': | |
return state + 1 | |
case 'DECREMENT': | |
return state - 1 | |
default: | |
return state | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// need node 6.9. run with: | |
// node redux-mini.js --harmony | |
function createStore(reducer, initialState) { | |
var currentReducer = reducer; | |
var currentState = initialState; | |
var listener = () => {}; | |
return { | |
dispatch(action) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class TestComponent { | |
ngOnInit() { | |
this.form = new FormGroup({...}); | |
this.valueChangesSubscription = this.form.valueChanges.subscribe(console.log); | |
this.statusChangesSubscription = this.form.statusChanges.subscribe(console.log); | |
} | |
ngOnDestroy() { | |
this.valueChangesSubscription.unsubscribe(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class TestComponent { | |
constructor(private route: ActivatedRoute, private router: Router) { } | |
ngOnInit() { | |
this.route.params.subscribe(console.log); | |
this.route.queryParams.subscribe(console.log); | |
this.route.fragment.subscribe(console.log); | |
this.route.data.subscribe(console.log); | |
this.route.url.subscribe(console.log); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class TestComponent { | |
constructor(private renderer: Renderer2, | |
private element : ElementRef) { } | |
ngOnInit() { | |
this.clickSubscription = this.renderer.listen(this.element.nativeElement, "click", handler); | |
} | |
ngOnDestroy() { | |
this.clickSubscription.unsubscribe(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class TestComponent { | |
constructor(private element : ElementRef) { } | |
interval: Subscription; | |
click: Subscription; | |
ngOnInit() { | |
this.intervalSubscription = Observable.interval(1000).subscribe(console.log); | |
this.clickSubscription = Observable.fromEvent(this.element.nativeElement, 'click').subscribe(console.log); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class TestComponent { | |
constructor(private store: Store) { } | |
todos: Subscription; | |
ngOnInit() { | |
this.todosSubscription = this.store.select('todos').subscribe(console.log); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'test', | |
template: `<todos [todos]="todos$ | async"></todos>` | |
}) | |
export class TestComponent { | |
constructor(private store: Store) { } | |
ngOnInit() { | |
this.todos$ = this.store.select('todos'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class TestDirective { | |
@HostListener('click') | |
onClick() { | |
.... | |
} | |
} |