Merge hooks and subscriptions into "events".
See original GitHub issueI’d like to simplify the API a bit more without losing functionality / power or compromising speed. I think this is possible by removing subscriptions and hooks and introducing a new concept: events.
app({
events: {
/* replaces subscriptions*/
onLoad: [ (state, actions), ... ],
/* below are the hooks you already know */
onAction: [ (state, action, data), ... ],
onUpdate: [ (oldState, newState, data), ... ],
onRender: [ (state, actions, view), ... ],
onError: [ (state, error), ... ]
}
})
- Newcomers have a concept less to learn and a single signature to remember when using events.
- Easier for plugins to add new events, for example the Router and onRoute.
Example 1
Before
app({
subscriptions: [
(model, actions) => actions.doSomething()
]
})
After
app({
events: {
onLoad: (state, actions) => actions.doSomething()
}
})
Example 2
Before
app({
hooks: {
onAction: (action, data) => console.log(action, data)
}
})
After
app({
events: {
onAction: [
(state, action, data) => console.log(action, data)
]
}
})
Issue Analytics
- State:
- Created 6 years ago
- Reactions:11
- Comments:19 (11 by maintainers)
Top Results From Across the Web
Service hooks events - Azure DevOps
Event : A merge commit was created on a pull request. Publisher ID: tfs; Event ID: git.pullrequest.merged; Resource Name: pullrequest. Settings.
Read more >Merging a pull request should trigger a event for the ...
When a pull request is merged into a repository a commit event should be triggered via the configured webhooks.
Read more >Repository Hooks and Merge Checks Guide
Repository hooks and merge checks can be used to enforce policies on your commits and branches, or to trigger actions after a change...
Read more >Webhook events - GitLab Docs
A merge request is created, updated, merged, or closed, or a commit is added in the source branch. Wiki page event, A wiki...
Read more >Git hooks: How to automate actions in your Git repo
Git hooks are shell scripts found in the hidden .git/hooks directory of a ... These scripts trigger actions in response to specific events, ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
👍 for the idea of mergeing subscriptions and hooks into "events.
I basically like @dodekeract’s signature normalization, except I think perhaps:
a) If we give all events the
model
(the current model) as first argument, thenonUpdate
doesn’t neednew
in the second argumentb) Wouldn’t it make sense to provide the “error” function to all the events as well (except for
onError
of course 😉 ) ?@jbucaran Can this be closed?