question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Merge hooks and subscriptions into "events".

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Reactions:11
  • Comments:19 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
zacenocommented, Mar 31, 2017

👍 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, then onUpdate doesn’t need new in the second argument

b) Wouldn’t it make sense to provide the “error” function to all the events as well (except for onError of course 😉 ) ?

1reaction
FlorianWendelborncommented, Apr 15, 2017

@jbucaran Can this be closed?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found