-
Notifications
You must be signed in to change notification settings - Fork 84
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
testing case: merge on atomic update #30
base: master
Are you sure you want to change the base?
Conversation
iofjuupasli
commented
Jun 8, 2015
result.push(d()); | ||
}); | ||
a(2); | ||
assert.deepEqual(result, [2, 5, 4, 6]); |
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.
Here I suppose that events will be emitted in the same order as streams provided to flyd.merge
.
Should that be like that? Or maybe opposite order, because of curry-in-mind API? Or maybe it should depends on order of stream declarations?
This is intended behavior. When From the section about atomic updates:
If the merged stream turned one entering event into two events the above would not be true and atomic updates wouldn't work. Does the above explanation make sense to you? Do you have a use case for the suggested behavior? |
Surprising. This behaviour seems broken
I think it's wrong preposition. Case approves that. Atomic updates should guarantee that Also right now it isn't true for async streams. I can emit one event, and then asynchronously emit more than one event in another stream. So, I think you should alter section in readme instead of introducing unexpected behaviour based on fallacy 'atomic equals one'. I think it's possible to have two event on one stream at one time. Most probably it's hard to implement in general.
No. But I can imagine that case (logging, show some messages to user (achievements)). |
Atomic updates means that when a stream changes all it's dependencies changes at the exact same time. Thus
What case?
Please explain this?
This should definitely be documented. But atomic doesn't equal one. In this context it means 'at once'. All updates happens 'at once'. Two changes from the same stream can't happen 'at once' and thus the behavior you request would go against the idea of atomic updates.
How so? Imagine that a stream is like a timeline with changes/events on it. You can have two changes/events infinitely close to each other but you can not have two changes that happens in the exact same moment. |
Test case.
var a = stream()
var b = stream([a], function(self){
self(1)
setTimeout(function(){self(2)}, 0);
}) For every emitted
Why? var a = stream();
a([new Event(1), new Event(2)]) I have abstracted it on my side, but that is really two events at once. |
A test case doesn't define correct behavior. I could easily create a passing test case that validates the current behavior.
Two event's enter the system here. One when you invoke
Because one property cannot have two different values at the same time.
Yes. You can use a stream of arrays to represent a stream that contains multiple values at the same time. That is not a problem. |
Right. But stream can be emitter of two different value at the same time. var weaponLeftHand = stream(1);
var weaponRightHand = stream(5);
var playerAction = stream()
var damageLeftHand = stream([playerAction], function () {
if (playerAction() === 'attack') {
return weaponLeftHand();
}
});
var damageRightHand = stream([playerAction], function () {
if (playerAction() === 'attack' && skills().indexOf('superpower') !== -1) {
return weaponRightHand();
}
});
var opponentResist = stream(3);
var damage = filter(function (damage) {
return damage > opponentResist();
}, merge([damageLeftHand, damageRightHand]));
var opponentHeals = scan(function (hp, damage) {
// this called twice because damage is stream
return hp - damage;
}, damage);
// but emmits only one event because this is property
var opponentHealsGui = map(function (hp) {
return '<div>' + hp + '</div>';
}, opponentHeals); I know, there is no stream/property in flyd.
The only problem with two events at time is state that depends on one last value or on order of events. Because we can't separate this two events in a time and say who was the last one and in which order apply events to property. I think that it's possible in theory. But practically implementing that will be not so simple, and using very rare and limited (associativity of operations on events). I think current behavior should be mentioned in readme in merge and atomic sections. |
Streams are more like properties. They have a current value. In the test case in your PR what would the value of This behavior is not something that I've invented. It might not be intuitive but when you consider what atomic updates mean I think it's the only thing that makes sense. Bacon doesn't have atomic updates for EventStreams. Elm drops values in What about doing something like this: var damageBothHands = stream([playerAction], function () {
var damage = 0;
if (playerAction() === 'attack') {
damage += weaponLeftHand();
}
if (playerAction() === 'attack' && skills().indexOf('superpower') !== -1) {
damage += weaponRightHand();
}
if (damage !== 0) return damage;
}); I understand that this is not as simple as if Flyd had the behavior you request. I'll think about this some more and see if I can think of a better solution.
I certainly agree and I will reopen this issue until that is done. I am sorry if this lack of documentation has been a hurdle for you. |
@iofjuupasli What about a |