Hyperapp: Normalize actions/events signatures.

Created on 19 Apr 2017  ·  5Comments  ·  Source: jorgebucaran/hyperapp

tl;dr

Make all functions in the API follow the same signature:

(state, actions, data, emit)


Now

  • view(state, actions)
  • actions.myAction(state, data, actions, emit)
  • events.loaded(state, actions, emit)
  • events.action(state, actions, data, emit)
  • events.update(state, actions, data, emit)
  • events.render(state, actions, data, emit)

After

  • view(state, actions)
  • actions.myAction(state, actions, data, emit)
  • events.loaded(state, actions, emit)
  • events.action(state, actions, data, emit)
  • events.update(state, actions, data, emit)
  • events.render(state, actions, data, emit)

Tentative: Pass the options (the same from app(options)) object to loaded as data, so it can match the proposed signature too. 🤔

Discussion

Most helpful comment

This is a breaking change, as you'll need to modify all your actions signature from:

(state, data, _actions_)

to

(state, _actions_, data)

@selfup @pedroborges @cdeutmeyer @lukejacksonn Are we okay with this?

All 5 comments

events.loaded(state, actions, emit) — @jbucaran

Maybe it's better to just use state, actions, _, emit here, where _ is (right now) always undefined? It streamlines everything and if we ever decide that we need data we don't have to break the API.

It's also not unheard of. JSON.stringify({}, null, '\t') is similarly used. Of course null doesn't have to be null here, but I've seen this a lot.

@dodekeract Good point!

This is a breaking change, as you'll need to modify all your actions signature from:

(state, data, _actions_)

to

(state, _actions_, data)

@selfup @pedroborges @cdeutmeyer @lukejacksonn Are we okay with this?

The difference between (s,a,d) and (s,d,a) has always niggled me and it would certainly mean one less thing for users to remember.. for these reasons I am all for it.

I also support @dodekeract's statement of using state, actions, _, emit for loaded. Just to keep things super consistent. Your proposal @jbucaran of passing options as the data for that function is also not a bad idea at all 👍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dwknippers picture dwknippers  ·  3Comments

jamen picture jamen  ·  4Comments

jorgebucaran picture jorgebucaran  ·  4Comments

VictorWinberg picture VictorWinberg  ·  3Comments

jorgebucaran picture jorgebucaran  ·  4Comments