fable-compiler / fable-arch

Framework for building applications based on the elm architecture.
https://fable-compiler.github.io/fable-arch/
Apache License 2.0
60 stars 14 forks source link

Move from mailboxprocessor to standard js events #41

Closed mastoj closed 8 years ago

mastoj commented 8 years ago

The mailboxprocessor is nice, but performance wise I think we could do much better with events. My thoughts are roughly this:

var elem = document.createElement("div"); // elem to hold state, will never be rendered
var handleEvent = function(e, post) {
    var data = e.details.data;
    var state = doSomeMagic(e.details, elem["state"]);
    elem["state"] = state;
}
var post = function(data) {
    var event  = new CustomEvent("ArchEvent", {details:{data: data}});
    elem.dispatchEvent(event);
}
elem.addEventListener("ArchEvent", function(e) { handleEvent(e,post)});

Here we create a element that will hold the state for things in the application, basically the same thing we use when we do the recursive call. We create a helper function for posting messages to that will be used to post messages on the element we created. That we just attach a event listener to the element and celebrates victory.

MangelMaxime commented 8 years ago

I would be interesting if we could give it a try.

Did you take a look at how others libraries are doing the Event parts ?

mastoj commented 8 years ago

didn't find an easy part that shows how they do it, but didn't look that much either to be honest :)

mastoj commented 8 years ago

Solved by #42