Fix bug where `this` was referring to the fields of a parent facet, not the facet currently being constructed
This commit is contained in:
parent
26d4a75318
commit
51a28b9349
|
@ -55,9 +55,9 @@ function buildActor(nameExpOpt, block, withReact) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function reactWrap(blockCode) {
|
function reactWrap(blockCode) {
|
||||||
return '{ Syndicate.Actor.Facet.build((function () { ' +
|
return '{ Syndicate.Actor.Facet.build(function () { ' +
|
||||||
blockCode +
|
blockCode +
|
||||||
' }).bind(this)); }';
|
' }); }';
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildOnEvent(isTerminal, eventType, subscription, projection, bindings, body) {
|
function buildOnEvent(isTerminal, eventType, subscription, projection, bindings, body) {
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
// bin/syndicatec compiler/demo-bad-this.js | node
|
||||||
|
//
|
||||||
|
// Bug with this-ness. Symptomatic output:
|
||||||
|
//
|
||||||
|
// + render one false
|
||||||
|
// + render two false
|
||||||
|
// present one
|
||||||
|
// - render one false
|
||||||
|
// - render two false
|
||||||
|
// + render one one
|
||||||
|
// + render two one
|
||||||
|
//
|
||||||
|
// Good output:
|
||||||
|
//
|
||||||
|
// + render one false
|
||||||
|
// + render two false
|
||||||
|
// present one
|
||||||
|
// - render one false
|
||||||
|
// + render one one
|
||||||
|
|
||||||
|
var Syndicate = require('./src/main.js');
|
||||||
|
|
||||||
|
assertion type user(who);
|
||||||
|
assertion type present(who);
|
||||||
|
assertion type rendered(who, isPresent);
|
||||||
|
|
||||||
|
ground dataspace {
|
||||||
|
actor {
|
||||||
|
assert user('one');
|
||||||
|
assert present('one');
|
||||||
|
}
|
||||||
|
|
||||||
|
actor {
|
||||||
|
assert user('two');
|
||||||
|
// assert present('two');
|
||||||
|
}
|
||||||
|
|
||||||
|
actor {
|
||||||
|
during user($who) {
|
||||||
|
field this.isPresent = false;
|
||||||
|
on asserted present(who) {
|
||||||
|
console.log('present', who);
|
||||||
|
this.isPresent = who;
|
||||||
|
}
|
||||||
|
on retracted present(who) {
|
||||||
|
console.log('absent', who);
|
||||||
|
this.isPresent = false;
|
||||||
|
}
|
||||||
|
assert rendered(who, this.isPresent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
actor {
|
||||||
|
during rendered($who, $isPresent) {
|
||||||
|
on start { console.log('+ render', who, isPresent); }
|
||||||
|
on stop { console.log('- render', who, isPresent); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -139,7 +139,9 @@ Facet.current = null;
|
||||||
|
|
||||||
Facet.build = function(f) {
|
Facet.build = function(f) {
|
||||||
var facet = new Facet(Dataspace.activeBehavior());
|
var facet = new Facet(Dataspace.activeBehavior());
|
||||||
withCurrentFacet(facet, f);
|
withCurrentFacet(facet, function () {
|
||||||
|
f.call(facet.fields);
|
||||||
|
});
|
||||||
facet.completeBuild();
|
facet.completeBuild();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue