Open paul-go opened 5 years ago
We would probably need some kind of priority system if we want this behavior.
const clicked = reflex(false);
const dblclicked = reflex(false);
const result = priotirizedreflex({});
ml.div(
on("click", () => result.set(1, clicked.flip() ? { attr: 1 } : {}))),
on("dblclick", () => result..set(2, dblclicked.flip() ? { attr: 2 } : {})))
);
initial condition would have 0 priority and set function's first argument can take priority of that object.
function calculatePrioritized(values){
const result = {};
values.sort((a, b) => a.priority - b.priority).forEach(x => {
Object.assign(result, x.data);
}
return result;
}
in most basic terms something like this.
calculatePrioritized([{priority: 1, data: {attr: 1}},{priority: 0, data: {attr: 2}}])
->{attr: 1}
calculatePrioritized([{priority: 1, data: {attr: 1}},{priority: 2, data: {attr: 2}}])
->{attr: 2}
calculatePrioritized([{priority: 1, data: {attr: 1}},{priority: 2, data: {attr: 2}}, {priority: 3, data:{}}])
->{attr: 2}
We should consider providing a kind of "undo" history on the attribute values applied to a branch. This is necessary when there are multiple recurrent functions affecting the same attribute. For example:
Behavior:
attr
to be set to 1.attr
to be set to 2.attr
to return to 1, the previous set value.At the current moment, the behavior actual behavior is a bit unpredictable (which is why I've labeled this as a bug)