-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a81d8db
commit 0654726
Showing
11 changed files
with
129 additions
and
17 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ɵɵdirectiveInject as directiveInject } from '@angular/core'; | ||
import { StoreonService } from './storeon.service'; | ||
|
||
|
||
/*** | ||
* | ||
* Experimental feature, works only with Ivy renderer | ||
* Patches the component with keys from storeon store | ||
* | ||
*/ | ||
export function UseStoreon<State, Events>(config: { | ||
keys: Array<keyof State>, | ||
dispatcher?: string | ||
}) { | ||
return (cmpType) => { | ||
const originalFactory = cmpType.ngComponentDef.factory; | ||
cmpType.ngComponentDef.factory = () => { | ||
const cmp = originalFactory(cmpType.ngComponentDef.type); | ||
|
||
const storeon = directiveInject<StoreonService<State, Events>>(StoreonService ); | ||
|
||
config.keys.forEach(key => cmp[key] = storeon.useStoreon(key)); | ||
|
||
if (config.dispatcher) { | ||
cmp[config.dispatcher] = storeon.dispatch.bind(storeon); | ||
} | ||
|
||
return cmp; | ||
}; | ||
|
||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div> | ||
<button (click)="increment()">Increment counter</button> | ||
<span>Total count: {{ count | async }}</span> | ||
</div> |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { HookCounterComponent } from './hook-counter.component'; | ||
|
||
describe('HookCounterComponent', () => { | ||
let component: HookCounterComponent; | ||
let fixture: ComponentFixture<HookCounterComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ HookCounterComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(HookCounterComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { UseStoreon } from '@storeon/angular'; | ||
import { Events, State } from '../app.module'; | ||
import { Dispatch } from 'storeon'; | ||
|
||
@Component({ | ||
selector: 'app-hook-counter', | ||
templateUrl: './hook-counter.component.html', | ||
styleUrls: ['./hook-counter.component.scss'] | ||
}) | ||
@UseStoreon<State, Events>({keys: [ 'count' ], dispatcher: 'dispatch'}) | ||
export class HookCounterComponent implements OnInit { | ||
|
||
count: Observable<number>; | ||
dispatch: Dispatch<Events>; | ||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
increment() { | ||
this.dispatch('inc'); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<ul> | ||
<li><a [routerLink]="['/counter']" routerLinkActive="router-link-active">Counter</a></li> | ||
<li><a [routerLink]="['/ivy-hook']" routerLinkActive="router-link-active">Counter with Ivy Hook</a></li> | ||
<li><a [routerLink]="['/counter1']" routerLinkActive="router-link-active">Counter 1</a></li> | ||
</ul> |