Skip to content

Commit

Permalink
Fixed breaking change from previous update, a... (#19)
Browse files Browse the repository at this point in the history
* Fixed breaking change from previous update, a...
  • Loading branch information
Svetomechc authored and irustm committed Jul 15, 2019
1 parent 1938ec4 commit 77c40f5
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 170 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Read more about Storeon **[article]**.

## Compatibility

*@storeon/angular* **0.3.0**+ requires *storeon* **0.9.0**+

*@storeon/angular* **0.2.0**+ supports Angular **8**

*@storeon/angular* **0.1.0** supports Angular **7**
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storeon/angular",
"version": "0.3.0",
"version": "0.3.1",
"description": "Storeon for Angular 🅰⚡",
"scripts": {
"ng": "ng",
Expand All @@ -24,28 +24,28 @@
}
],
"dependencies": {
"@angular/animations": "~8.2.0-next.0",
"@angular/common": "~8.2.0-next.0",
"@angular/compiler": "~8.2.0-next.0",
"@angular/core": "~8.2.0-next.0",
"@angular/forms": "~8.2.0-next.0",
"@angular/platform-browser": "~8.2.0-next.0",
"@angular/platform-browser-dynamic": "~8.2.0-next.0",
"@angular/router": "~8.2.0-next.0",
"@angular/animations": "~8.2.0-next.1",
"@angular/common": "~8.2.0-next.1",
"@angular/compiler": "~8.2.0-next.1",
"@angular/core": "~8.2.0-next.1",
"@angular/forms": "~8.2.0-next.1",
"@angular/platform-browser": "~8.2.0-next.1",
"@angular/platform-browser-dynamic": "~8.2.0-next.1",
"@angular/router": "~8.2.0-next.1",
"core-js": "^3.1.4",
"rxjs": "~6.5.2",
"storeon": "^0.9.1",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "0.801.0",
"@angular-devkit/build-ng-packagr": "0.801.0",
"@angular/cli": "8.1.0",
"@angular/compiler-cli": "~8.2.0-next.0",
"@angular/language-service": "~8.2.0-next.0",
"@angular-devkit/build-angular": "0.802.0-next.0",
"@angular-devkit/build-ng-packagr": "0.802.0-next.0",
"@angular/cli": "8.2.0-next.0",
"@angular/compiler-cli": "~8.2.0-next.1",
"@angular/language-service": "~8.2.0-next.1",
"@types/jasmine": "~3.3.13",
"@types/jasminewd2": "~2.0.6",
"@types/node": "~12.0.12",
"@types/node": "~12.6.2",
"codelyzer": "^5.1.0",
"fibers": "^4.0.1",
"jasmine-core": "~3.4.0",
Expand Down
6 changes: 3 additions & 3 deletions projects/ng-storeon/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@storeon/angular",
"version": "0.3.0",
"version": "0.3.1",
"description": "Storeon for Angular 🅰⚡",
"peerDependencies": {
"@angular/common": "^8.1.0",
"@angular/core": "^8.1.0",
"@angular/common": "^8.1.1",
"@angular/core": "^8.1.1",
"storeon": "^0.9.1"
},
"license": "MIT",
Expand Down
12 changes: 6 additions & 6 deletions projects/ng-storeon/src/lib/storeon.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ɵɵdirectiveInject as directiveInject } from '@angular/core';
import { StoreonService } from './storeon.service';

import { StoreonEvents } from 'storeon';

/***
*
* Experimental feature, works only with Ivy renderer
* Patches the component with keys from storeon store
*
*/
export function UseStoreon<State, Events>(config: {
export function UseStoreon<State, Events extends StoreonEvents<State> = any>(config: {
keys: Array<keyof State>,
dispatcher?: string
}) {
Expand All @@ -17,13 +17,13 @@ export function UseStoreon<State, Events>(config: {
cmpType.ngComponentDef.factory = () => {
const cmp = originalFactory(cmpType.ngComponentDef.type);

const storeon = directiveInject<StoreonService<State, Events>>(StoreonService );
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);
}
if (config.dispatcher) {
cmp[config.dispatcher] = storeon.dispatch.bind(storeon);
}

return cmp;
};
Expand Down
4 changes: 2 additions & 2 deletions projects/ng-storeon/src/lib/storeon.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestBed } from '@angular/core/testing';
import createStore, { StoreonEvents } from 'storeon';
import { Store, StoreonEvents } from 'storeon';
import { StoreonService } from './storeon.service';
import { STOREON } from './storeon.token';

Expand All @@ -8,7 +8,7 @@ interface MockEvents extends StoreonEvents<typeof mockState> {
'action': { data: string };
}

const mockStore: createStore.Store<typeof mockState, MockEvents> = {
const mockStore: Store<typeof mockState, MockEvents> = {
on: jasmine.createSpy('on').and.callFake((event, callback) => {
callback(mockState);
}),
Expand Down
9 changes: 5 additions & 4 deletions projects/ng-storeon/src/lib/storeon.service.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Injectable, Inject, OnDestroy } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { distinctUntilChanged, map, pluck } from 'rxjs/operators';
import createStore from 'storeon';
import { Store, StoreonEvents } from 'storeon';
import { STOREON } from './storeon.token';

@Injectable({
providedIn: 'root'
})
export class StoreonService<State, Events> implements OnDestroy {
export class StoreonService<State, Events extends StoreonEvents<State> = any> implements OnDestroy {

private state$ = new BehaviorSubject<State>(this.store.get());

private readonly unbind: Function;

constructor(@Inject(STOREON) private store: createStore.Store<State>) {
constructor(@Inject(STOREON) private store: Store<State, Events>) {
this.unbind = this.store.on('@changed', (state) => {
this.state$.next({ ...state as any });

Expand Down Expand Up @@ -42,7 +42,8 @@ export class StoreonService<State, Events> implements OnDestroy {
return mapped$.pipe(distinctUntilChanged());
}

dispatch<E extends Events, K extends keyof E>(event: K, data?: E[K]) {
dispatch<K extends keyof Events>(event: K, data?: Events[K]) {
// @ts-ignore
this.store.dispatch(event, data);
}

Expand Down
Loading

0 comments on commit 77c40f5

Please sign in to comment.