-
Notifications
You must be signed in to change notification settings - Fork 7
#113 - Implement experimental web worker support #114
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
Conversation
@@ -1 +0,0 @@ | |||
require('skatejs-build'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boyscout: totes unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The build doesn't work now, is it because of this?
sd.diff({ | ||
destination, | ||
source, | ||
done (instructions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the tentatively proposed API: provide a done
callback and if workers are available it uses them. Still need to patch render
/ merge
to handle this.
@@ -66,10 +66,12 @@ function translateFromReact (item) { | |||
return item; | |||
} | |||
|
|||
let count = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely better ways, but this gets the initial spike working.
// import WeakMap from './weak-map'; | ||
// export default new WeakMap(); | ||
const map = []; | ||
export default { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't use weakmaps if we're using scalar values as keys.
|
||
export default { | ||
diff, | ||
merge, | ||
patch, | ||
render, | ||
types, | ||
vdom, | ||
version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boyscout: removed this as it was way out of sync.
Running sk-build should work.
…On Thu., 1 Dec. 2016, 23:08 Matthew Phillips, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In gulpfile.js <#114>:
> @@ -1 +0,0 @@
-require('skatejs-build');
The build doesn't work now, is it because of this?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#114>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAIVbBMb0VazNQKA1jEc6--k1uD4ISdFks5rDrjagaJpZM4LA_VS>
.
|
On mobile. Will try in an hour or so when on lappy.
…On Thu., 1 Dec. 2016, 23:17 Trey Shugart, ***@***.***> wrote:
Running sk-build should work.
On Thu., 1 Dec. 2016, 23:08 Matthew Phillips, ***@***.***>
wrote:
***@***.**** commented on this pull request.
------------------------------
In gulpfile.js <#114>:
> @@ -1 +0,0 @@
-require('skatejs-build');
The build doesn't work now, is it because of this?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#114>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAIVbBMb0VazNQKA1jEc6--k1uD4ISdFks5rDrjagaJpZM4LA_VS>
.
|
Hm, I don't have a |
Darn. Npm install should do that. Can't check atm but can in 45mins ish.
…On Thu., 1 Dec. 2016, 23:28 Matthew Phillips, ***@***.***> wrote:
Hm, I don't have a node_modules/.bin/sk-build, is that something I need
to install globally?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#114 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAIVbF797H7_bHs9QQf4-VXfKADpfI7tks5rDr1ogaJpZM4LA_VS>
.
|
Are you using both rollup and webpack? Or maybe transitioning from one to another? |
About the API, I think it's a good API for a lot of use cases, but in my case I'm already running inside of a web worker, so I don't need to launch another worker. I'll be diffing 2 plain objects in the worker, sending the patch instructions back to the window and applying the patches there. To keep my file-size down I'll probably use rollup, does the use of the webpack plugin here break rollup usage (even if you don't wind up using that functionality)? I could maybe just pull in dom-diff/src/diff-main.js directly since that's what I need on the worker since, then pull in dom-diff/src/patch.js on the window side. |
It should produce an artefact for the worker that you can load from dist
for diffing.
…On Thu., 1 Dec. 2016, 23:56 Matthew Phillips, ***@***.***> wrote:
About the API, I think it's a good API for a lot of use cases, but in my
case I'm already running inside of a web worker, so I don't need to launch
another worker. I'll be diffing 2 plain objects in the worker, sending the
patch instructions back to the window and applying the patches there.
To keep my file-size down I'll probably use rollup, does the use of the
webpack plugin here break rollup usage (even if you don't wind up using
that functionality)? I could maybe just pull in dom-diff/src/diff-main.js
directly since that's what I need on the worker since, then pull in
dom-diff/src/patch.js on the window side.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#114 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAIVbGOUkhBRGpr_QwuNVbWjLIT8wpkvks5rDsPsgaJpZM4LA_VS>
.
|
Either way, yeah, you should be able to load the diff main in a worker,
that's what diff-worker does. You just need the deps that the worker-loader
gives you.
…On Fri., 2 Dec. 2016, 00:01 Trey Shugart, ***@***.***> wrote:
It should produce an artefact for the worker that you can load from dist
for diffing.
On Thu., 1 Dec. 2016, 23:56 Matthew Phillips, ***@***.***>
wrote:
About the API, I think it's a good API for a lot of use cases, but in my
case I'm already running inside of a web worker, so I don't need to launch
another worker. I'll be diffing 2 plain objects in the worker, sending the
patch instructions back to the window and applying the patches there.
To keep my file-size down I'll probably use rollup, does the use of the
webpack plugin here break rollup usage (even if you don't wind up using
that functionality)? I could maybe just pull in dom-diff/src/diff-main.js
directly since that's what I need on the worker since, then pull in
dom-diff/src/patch.js on the window side.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#114 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAIVbGOUkhBRGpr_QwuNVbWjLIT8wpkvks5rDsPsgaJpZM4LA_VS>
.
|
Fixed the rollup build issue. Now generating a |
So, I don't know if you answered this, but since you are using import { diff } from 'skatejs-dom-diff'; Will this work or blow up, aren't you using a webpack config in src/diff.js or am I just confused? |
You're right. I'll remove that. Travelling between Syd and Mel right now
which is why my responses have been patchy :) I'll have a look a bit later.
…On Fri., 2 Dec. 2016, 08:43 Matthew Phillips, ***@***.***> wrote:
So, I don't know if you answered this, but since you are using jsnext
config, a rollup user might do:
import { diff } from 'skatejs-dom-diff';
Will this work or blow up, aren't you using a webpack config in
src/diff.js or am I just confused?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#114 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAIVbOQruULht3WdLjv8a1Ybsa8SHdFMks5rDz-CgaJpZM4LA_VS>
.
|
ids don't seem to work, I guess because it assumes your nodes are created with Also, if one Node is created in the worker and another in the window their ids aren't going to match up. I'm pretty sure this is why React has ids that look like I wrote a library for this purpose about a year ago: https://github.com/canjs/node-route/blob/master/src/dom-id.js The inline docs do a decent job of explaining what is going on. Of particular interest are This could wind up being a bigger change that you were probably anticipating, I imagine, so I would understand if you don't want to pursue it further. |
This is intentional as there's no way to transfer a DOM node from the real DOM to a web worker. A way around this would be to extract information from each node and give it an id at that point in time. Unfortunately this would involve building a virtual tree from the entire real tree on the main thread. Basically the inverse of the What's the use case for needing to diff a real tree in a worker? |
You need to construct a virtual tree from the real tree once, when the page loads, if you ever intend to patch the real tree. I want to build the virtual tree on page load, send it to a worker, and from that point on only patch that virtual tree against other virtual trees, sending the patch instructions back to the window and applying the patches on the real tree. |
…ent and predictable.
…e unnecessary ones.
…onversion. Remove old APIs. BREAKING CHANGE: major refactor
Massive update. I've added both import { diff, toVdom } from 'skatejs-dom-diff';
const vTree = toVdom(document.getElementById('app'));
diff(vTree, myNewTree, {
done (instructions) {
patch(instructions);
}
}); That said, the import { render } from 'skatejs-dom-diff';
const renderer = render(root => (
<div>I was rendered in {root.id}!</div>
));
renderer(document.getElementById('app')); Understand if you've moved on, but I've quite enjoyed just tinkering on it. Fun project. |
Yeah no doubt, I think this is a real differentiator for the project, as I've explored all of them just about and most do not break out diffing and patching in this way. I'm happy with idom but definitely am not married to it. I have plans for creating benchmarking for vdom through web workers approaches. In the meantime I still have a branch of my project using dom diff so I'll try out these changes and let you know. |
Implements #40, #113.