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

Deku Override #417

Open
iazel opened this issue Apr 8, 2016 · 0 comments
Open

Deku Override #417

iazel opened this issue Apr 8, 2016 · 0 comments

Comments

@iazel
Copy link

iazel commented Apr 8, 2016

Hello,
I've made a generic List component, however to do it I had to replace a large portion of Deku, more precisely the createElement and updateElement.
To have a generic List that accept any kind of component, I need to wrap any actions dispatched by its children and to do this, I need two wrap the dispatch itself.
Therefore I've added a new optional property to the vnode: override. For now I used it to override the dispatch but it could be used for any parts of the model.

During the HTML element creation, I check if the vnode want to override something or not. The addons per se is very small:

function createThunk(vnode, path, dispatch, context) {
  /* ... head ... */
  let model = overrideModel(vnode, {
    children,
    props,
    path,
    dispatch,
    context
  })
 /* ... tail ... */
}

// same thing for updateThunk

function overrideModel(vnode, model) {
  if(typeof vnode.override !== 'object')
    return model

  const override = vnode.override
  Object.keys(override).forEach((k) => {
    model[k] = override[k]( model[k] )
  }) 
  return model
}

Then I can override dispatch with:

vnode.override.dispatch = (dispatch) => (action) => wrap(action)

However I had to replace the entire dom and createApp, because this two functions are deeply nested.

You can see the results of this work at this repo List of Counters.

I don't know if it's good to implement this kind of overriding, however would be great to have the possibility to easily replace the create and update functions. I'm thinking on it...

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

1 participant