Comments (9)
Hello @chekoopa , thank you for your suggestion.
Some use cases can be accomplished by (carefully) using the innerHtml
attribute (e.g., markdown rendering) or using signals. That being said, keys, thunks and hooks would indeed be a great addition.
Perhaps you could adapt the work for hooks in your fork to flame? PRs are always welcome :)
As for keys and thunks, I think neither is very complex to implement (key
for example is just a snabbdom attribute). Maybe this could fit in the following release, tho I still need time to research.
from purescript-flame.
Both innerHtml
and signals (and even effects with getElementById
, we used to have that) are dirty hacks, IMHO.
The problem is Hedwig having a different 'vnode baking' architecture, so I can't adapt it straightforward. However, I've researched your code for a bit and have some picture in mind about hooks implementation, would try carve some time and make a fork.
BTW, key
also can be added as NodeData. It may be a little unusual to have a vnode key as an attribute, but Hedwig has the same UX.
from purescript-flame.
Both innerHtml and signals (and even effects with getElementById, we used to have that) are dirty hacks, IMHO.
More often than not, hah.
The problem is Hedwig having a different 'vnode baking' architecture, so I can't adapt it straightforward. However, I've researched your code for a bit and have some picture in mind about hooks implementation, would try carve some time and make a fork.
Sure!
BTW, key is also can be added as NodeData. It may be a little unusual to have a vnode key as an attribute, but Hedwig has the same UX.
That makes it easier to use/modify functions that construct nodes.
from purescript-flame.
I wonder if hooks should have the message return type, like events.
It seems to be possible (like, wrap hook functions with updater
), but we also should somehow include VNode mutation, and the current UX (Hedwig-based) is only acceptable for foreign functions (because of unsafe VNode mutations).
So, I'm now implementing the unsafe-foreign hook feature.
from purescript-flame.
Actually, safe-ish VNode mutation could be reached with map-like hook function, which returns new VNode object, and the under-the-hood wrapper performs data replacement (I don't know what would happen if we replace the whole node).
And all hook functions are Effect Unit
, if we're talking in Purs conventions.
So, if we would make wrapped Purs-compatible hook functions, they would look like this:
Name | Classic arguments | Possible Purs signature |
---|---|---|
init | vnode | VNode -> Effect VNode |
create | emptyVnode, vnode | VNode -> VNode -> Effect VNode |
insert | vnode | VNode -> Effect VNode |
prepatch | oldVnode, vnode | VNode -> VNode -> Effect VNode |
update | oldVnode, vnode | VNode -> VNode -> Effect VNode |
postpatch | oldVnode, vnode | VNode -> VNode -> Effect VNode |
destroy | vnode | VNode -> Effect Unit |
remove | vnode, removeCallback | VNode -> Effect Unit -> Effect Unit ยน |
ยน Don't know whether this hook should be implemented.
But, there's a big problem about vnodes. Snabbdom doesn't restrict adding custom properties to VNodes, and we are using that in our Markdown implementation. Elm Markdown library uses local model data (https://github.com/evancz/elm-markdown/blob/3.0.2/src/Native/Markdown.js), which stays with the node and is used for diffing. We add two fields, too, as for a local node model.
exports.start = function (options) {
return function (rawText) {
return function (vnode) {
return function () {
vnode.raw = rawText;
vnode.options = options;
vnode.elm.innerHTML = marked(rawText, formatOptions(options));
};
};
}
};
exports.patch = function(options) {
return function (rawText) {
return function (oldVnode) {
return function (vnode) {
return function () {
var oldRaw = oldVnode.raw || "";
var oldOptions = oldVnode.options || null;
vnode.raw = rawText;
vnode.options = options;
if (oldRaw === rawText && optionsEqual(oldOptions, options)) {
return;
}
vnode.elm.innerHTML = marked(rawText, formatOptions(options));
};
};
};
}
};
With Purs-based implementation it wouldn't be possible. If only we added another field, like model :: Object Type
, which would be empty for default nodes, but is usable with foreign and unsafe functions for model operations.
from purescript-flame.
Would all of that be easier if we changed the wrapper functions e.g. Renderer.purs to foreign calls? Similar to what hedwig did. Maybe as more features are added, changing (a bit of) type safety for easiness and performance is an acceptable trade off.
I am not sure I follow the need for the local vnode model
field. Aren't all vnode manipulations done in unsafe js? Would it be just to feed the initial values?
from purescript-flame.
It depends on what you have in mind for Flame. I'm not sure what functions could be converted to foreign (still not fully examined all the renderer internals), but the current state of code is pretty sturdy. The performance point is about benchmarking, I think.
By design, these manipulations are unsafe. The thing I've described above is kind of concept for Purs-compliant low-level FRP vnode hooking. Hooks themselves are rather advanced feature which used mostly by library developers (in Elm it was possible before the 0.19 release).
So, unsafe hooks are fair for now.
Aside of hooks, keys, and thunks Snabbdom offers module feature. But something tells me that would be too bloated.
from purescript-flame.
A question about naming conventions. What should we use for hooks' name?
- own naming, like
atInsert
. I've used that in Hedwig, it makes hooks distinctive from other attrs. - event-like naming, like
onInsert
. It doesn't interfere with events. - plain hook's name, like
insert
.
I'm now sticking with the first variant, but can change it at any moment before PR.
from purescript-flame.
Yeah I plan on adding benchmarks next. The types for hooks, and the first naming convention, sound fine. I will try it out on own my markdown generation too.
from purescript-flame.
Related Issues (20)
- Move CI to Github Actions HOT 1
- `lazy` with mutliple html composition layers appears to cause runtime errors / other odd behavior HOT 6
- Doctype HOT 2
- Monoid instance for Html a HOT 5
- Make Flame.Types.Html a real type HOT 1
- Internationalisation HOT 6
- Grouping elements in SVG
- No <kbd> tag
- Conditional rendering of fragments
- impossible to execute the ssr example HOT 6
- impossible to build examples HOT 2
- Integrating external element HOT 5
- The `tabindex` attribute does not work due to capitalization HOT 3
- Why not use /\ instead of :> for Tuple operator? HOT 1
- Question about Stale model in `AffUpdate` HOT 1
- Bug when using a function as the type of a message HOT 2
- `ReferenceError: document is not defined` on `spago run` HOT 1
- friction at running examples
- HTML elements with empty array of attributes and/or children
- Trivial ToClassList instance HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from purescript-flame.