-
Notifications
You must be signed in to change notification settings - Fork 131
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
How to work with different DOM? #348
Comments
Yeah the diff functions just return an array of those actions. You can see how it's used in dom/patch.js. I think we'll need to expose the diff function if we're not already. Then you just need to make your own patch function. I don't know much about pixi so I won't be that much help with that exactly. |
Why do I need my own patch? Can't I just refined only actions? Patch logic should be the same, go throw nodes and apply actions. |
Maybe I'm not following exactly what you meant. I thought you meant you wanted to create your own custom renderer. If you just want to apply it to some random piece of DOM, we could expose both the |
I am thinking about this ideal scenario Pixi has its own object model, something like this
I can create virtual dom.
then I would do something like this
Ideally, I would need to implement only two parts
and patch Actions, something like this
All other logic should be the same as for html, so it could be reused. Is deku support something like this? |
Yeah you should be able to do that. I'll reply with a bit more detail later today. You would still just need a custom |
This should be fairly straightforward, you'll just need to do something similar to the DOM renderer. You might have an API like this. // This will function roughly the same as the DOM root element
let pixiNode = new Container()
// Create a function to render the lastest vnode
let render = createPixiRenderer(container) You can follow the DOM renderer pretty closely, you'll need:
The update function would work something like this: import {diff} from 'deku'
const {Actions, diffNode} = diff // This is the API we'd need to expose
export default function patch (pixiNode, action) {
Actions.case({
setAttribute: (name, value, previousValue) => {
},
removeAttribute: (name, previousValue) => {
},
insertBefore: (index) => {
},
sameNode: () => {
},
updateChildren: (changes) => {
changes.forEach(change => {
Actions.case({
insertChild: (vnode, index, path) => {
pixiNode.addChild(new Text(vnode.nodeValue))
},
removeChild: (index) => {
},
updateChild: (index, actions) => {
}
}, change)
})
},
updateThunk: (prev, next, path) => {
// If you want lazy-rendered vnodes
},
replaceNode: (prev, next, path) => {
},
removeNode: (prev) => {
}
}, action)
} It shouldn't be too hard to put together. I'll make sure you can access the diff in the next release. |
Making a render for Two or Fabric would be similar. I might try getting something like Two working as it should be fairly simple. |
Thanks.
When would it be? |
Deku has this Actions abstraction https://github.com/dekujs/deku/blob/master/src/diff/index.js#L11
Does it mean you can work with any dom and not just html?
For example, I want to use deku with pixi.js library which has its own DOM.
If it's possible, is there any example how can I do it?
The text was updated successfully, but these errors were encountered: