Skip to content

Instantly share code, notes, and snippets.

View stevermeister's full-sized avatar
🇺🇦

Stepan Suvorov stevermeister

🇺🇦
View GitHub Profile
function createStore(reducer, initialState) {
var currentReducer = reducer;
var currentState = initialState;
var listener = () => {};
return {
getState() {
return currentState;
},
dispatch(action) {
function counter(state = 0, action) {
switch (action.type) {
case 'INCREMENT':
return state + 1
case 'DECREMENT':
return state - 1
default:
return state
}
}
// 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) {
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();
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);
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();
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);
export class TestComponent {
constructor(private store: Store) { }
todos: Subscription;
ngOnInit() {
this.todosSubscription = this.store.select('todos').subscribe(console.log);
}
@Component({
selector: 'test',
template: `<todos [todos]="todos$ | async"></todos>`
})
export class TestComponent {
constructor(private store: Store) { }
ngOnInit() {
this.todos$ = this.store.select('todos');
export class TestDirective {
@HostListener('click')
onClick() {
....
}
}