Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dispatch #15

Open
tarsisexistence opened this issue Jun 17, 2019 · 7 comments
Open

dispatch #15

tarsisexistence opened this issue Jun 17, 2019 · 7 comments

Comments

@tarsisexistence
Copy link

I think we can design a much better way to dispatch the things

at least we have to think about that
I still keep in mind that we can leave it as it is.

There are several important factors to consider:

  • size / complexity (should remain simple)
  • decorators (still aren't stable)
  • design (it should be comfortable to use without overheads)
@irustm
Copy link
Member

irustm commented Jun 20, 2019

I think we should look at angular ivy.

And make one decorator (example):

@Component({
...
})
@UseStoreon({
  states:['count'],
  dispatcher: 'dispatch'
})
export class FooComponent {
 public count: Observable<number>;
 public dispatch: Function;
}

and template:

<button (click)="dispatch('inc')">
<span>{{count | async}}</span>

like: https://ngxf.gitbook.io/platform/hooks/state-hook
without *useState directive

@tarsisexistence
Copy link
Author

@irustm it would be fair if I ask -- will storeon/angular support older versions?
I mean, Angular without Ivy in the box.

Yeah, right now peerDependencies are pointed strictly to angular 8+, but not all of the angular projects use version 8

btw, I think your idea is pretty good

@irustm
Copy link
Member

irustm commented Jun 20, 2019

I want the storeon to be used only with Angular Ivy. I hope that Angular Ivy projects will really be 3Kb.

For the rest, there are other big solutions, like ngrx, ngxs, akita.

@Svetomechc
Copy link
Contributor

Svetomechc commented Jun 25, 2019

@maktarsis I updated dispatch in #18 (if it gets merged) a little. Readme also:

image

@irustm you forgot to mention ngxf :D The idea you said above is actually similar to reducer hook.

@irustm
Copy link
Member

irustm commented Jun 25, 2019

@Svetomechc yeah, ngxf: #15 (comment)

like: https://ngxf.gitbook.io/platform/hooks/state-hook
without *useState directive

@Svetomechc
Copy link
Contributor

@irustm oh, yeah, didn't see that.
I summon @thekiba! (:

@thekiba
Copy link

thekiba commented Jul 9, 2019

I think it should be like this:

@UseStoreon()
@Component({
  selector: 'app-foo',
  template: `
    <button (click)="inc()">
    <span>{{ count | async }}</span>
  `
})
class FooComponent {
  @StoreonState('count') count: StoreonState<State, 'count'>;
  @StoreonEvent('inc') inc: StoreonEventFn<Event>;
}

But I don't like when using decorators with expected types, because TypeScript unsupported type checking with it. So, we can use simple functions for this:

@UseStoreon()
@Component({
  selector: 'app-foo',
  template: `
    <button (click)="inc()">
    <span>{{ count | async }}</span>
  `
})
class FooComponent {
  // will select 'count' from state and returns Observable<State['count']>
  count = useStoreonState<State>('count'); 
  // will create EventFn<Event> function for using as dispatch
  inc = useStoreonEvent<Event>('inc');
}

@UseStoreon() decorator will inject Storeon inner our component, and process states and event hooks. But maybe is not needed, because we can use inject function from @angular/core to get dependencies in useStoreonState and useStoreonEvent hooks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants