Skip to content
This repository was archived by the owner on Mar 26, 2021. It is now read-only.

Add option to set current React instance. #3

Closed
rmorshea opened this issue Mar 19, 2021 · 6 comments
Closed

Add option to set current React instance. #3

rmorshea opened this issue Mar 19, 2021 · 6 comments

Comments

@rmorshea
Copy link
Member

This line makes it hard to work with IDOM client-side because it's bound to the React instance that was built into the client. However we could work around that by doing the following instead I think:

let currentCreateElement = react.createElement;
let html = htm.bind(currentCreateElement);

function bindElementConstructor(createElement) {
  if (createElement !== currentCreateElement) {
    html = htm.bind(createElement)
  }
}

This way downstream clients can set what React instance is being used

@rmorshea
Copy link
Member Author

See here as well: developit/htm#203

@rmorshea
Copy link
Member Author

Doing this would break the component cookiecutter, but I had been thinking that we should make the components completely independent. Instead of just doing:

React.createComponent(userModule.userComponent)

The userModule would have a mount function that accepted the element in the DOM they should attach to. From there it'd be entirely up to the component on what it wants to do. The component could be React or it could even be Vue. The point is that it'd be completely separate and thus simpler to deal with.

This does make the idea of just people able to idom.install react components a bit awkward though since they won't know to abide by the same rules. There's probably a way to work around that though.

I think the fact that I need this rollup plugin to mangle the imports into the right thing tells me I'm trying to do something that I shouldn't be doing.

@rmorshea
Copy link
Member Author

Maybe the interface is userModule.mount(component, element) which would mean that you could just make userModule.mount = React.render as well as give yourself the flexibility to work with another (or even no) framework.

@rmorshea
Copy link
Member Author

This change should be made before updating idom-jupyter, and friends.

@rmorshea
Copy link
Member Author

Actually these are really two separate issues. The latter is easier to solve and can be done independently. See: #4

@rmorshea
Copy link
Member Author

This needs some more thought

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

No branches or pull requests

1 participant