diff --git a/examples/location/index.expanded.js b/examples/location/index.expanded.js index 9c43c40..ab71b3a 100644 --- a/examples/location/index.expanded.js +++ b/examples/location/index.expanded.js @@ -105,7 +105,7 @@ Syndicate.Actor.createFacet() }); } } -var _cachedAssertion1468253787297_0 = (function() { var _ = Syndicate.__; return fromBroker(wsurl, locationRecord(id, email, _, _, _)); })(); +var _cachedAssertion1468254187624_0 = (function() { var _ = Syndicate.__; return fromBroker(wsurl, locationRecord(id, email, _, _, _)); })(); Syndicate.Actor.createFacet() .addInitBlock((function() { marker.addListener('click', Syndicate.Dataspace.wrap(function () { @@ -132,6 +132,6 @@ Syndicate.Actor.createFacet() marker.setMap(null); if (selectedMarker === marker) selectedMarker = null; })) -.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468253787297_0, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468253787297_0, metalevel: 0 }; }), (function() {})).completeBuild(); })).completeBuild(); })(); +.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468254187624_0, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468254187624_0, metalevel: 0 }; }), (function() {})).completeBuild(); })).completeBuild(); })(); }); }).startStepping(); diff --git a/examples/todo/index.expanded.js b/examples/todo/index.expanded.js index f675bad..fa24f08 100644 --- a/examples/todo/index.expanded.js +++ b/examples/todo/index.expanded.js @@ -54,10 +54,10 @@ function todoListItemView(id) { (function () { Syndicate.Actor.createFacet() .onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(todo(id, _, _), 0); }), (function() { var _ = Syndicate.__; return { assertion: todo(id, (Syndicate._$("title")), (Syndicate._$("completed"))), metalevel: 0 }; }), (function(title, completed) { -var _cachedAssertion1468253788491_0 = (function() { var _ = Syndicate.__; return todo(id, title, completed); })(); +var _cachedAssertion1468254188794_0 = (function() { var _ = Syndicate.__; return todo(id, title, completed); })(); Syndicate.Actor.createFacet() .onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(show(completed), 0); }), (function() { var _ = Syndicate.__; return { assertion: show(completed), metalevel: 0 }; }), (function() { -var _cachedAssertion1468253788491_1 = (function() { var _ = Syndicate.__; return show(completed); })(); +var _cachedAssertion1468254188794_1 = (function() { var _ = Syndicate.__; return show(completed); })(); Syndicate.Actor.createFacet() .addAssertion((function() { var _ = Syndicate.__; return Syndicate.Patch.assert(this.ui.html('.todo-list', Mustache.render(getTemplate(this.editing @@ -70,8 +70,8 @@ Syndicate.Actor.createFacet() checked: completed ? "checked" : "", }), id), 0); })) -.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468253788491_1, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468253788491_1, metalevel: 0 }; }), (function() {})).completeBuild(); })) -.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468253788491_0, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468253788491_0, metalevel: 0 }; }), (function() {})).completeBuild(); })) +.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468254188794_1, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468254188794_1, metalevel: 0 }; }), (function() {})).completeBuild(); })) +.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468254188794_0, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468254188794_0, metalevel: 0 }; }), (function() {})).completeBuild(); })) .onEvent(false, "message", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(this.ui.event('.toggle', 'change', _), 0); }), (function() { var _ = Syndicate.__; return { assertion: this.ui.event('.toggle', 'change', (Syndicate._$("e"))), metalevel: 0 }; }), (function(e) { Syndicate.Dataspace.send(setCompleted(id, e.target.checked)); })) @@ -119,31 +119,31 @@ Syndicate.Actor.createFacet() (function () { Syndicate.Actor.createFacet() .onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(activeTodoCount(_), 0); }), (function() { var _ = Syndicate.__; return { assertion: activeTodoCount((Syndicate._$("count"))), metalevel: 0 }; }), (function(count) { -var _cachedAssertion1468253788491_2 = (function() { var _ = Syndicate.__; return activeTodoCount(count); })(); +var _cachedAssertion1468254188794_2 = (function() { var _ = Syndicate.__; return activeTodoCount(count); })(); Syndicate.Actor.createFacet() .addAssertion((function() { var _ = Syndicate.__; return Syndicate.Patch.assert(this.ui.context('count').html('.todo-count strong', '' + count), 0); })) .addAssertion((function() { var _ = Syndicate.__; return (count !== 1) ? Syndicate.Patch.assert(, 0) : Syndicate.Patch.emptyPatch; })) -.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468253788491_2, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468253788491_2, metalevel: 0 }; }), (function() {})).completeBuild(); })) +.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468254188794_2, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468254188794_2, metalevel: 0 }; }), (function() {})).completeBuild(); })) .onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(totalTodoCount(0), 0); }), (function() { var _ = Syndicate.__; return { assertion: totalTodoCount(0), metalevel: 0 }; }), (function() { -var _cachedAssertion1468253788491_3 = (function() { var _ = Syndicate.__; return totalTodoCount(0); })(); +var _cachedAssertion1468254188794_3 = (function() { var _ = Syndicate.__; return totalTodoCount(0); })(); Syndicate.Actor.createFacet() .addAssertion((function() { var _ = Syndicate.__; return Syndicate.Patch.assert(Syndicate.UI.uiAttribute('section.main', 'class', 'hidden'), 0); })) .addAssertion((function() { var _ = Syndicate.__; return Syndicate.Patch.assert(Syndicate.UI.uiAttribute('footer.footer', 'class', 'hidden'), 0); })) -.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468253788491_3, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468253788491_3, metalevel: 0 }; }), (function() {})).completeBuild(); })) +.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468254188794_3, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468254188794_3, metalevel: 0 }; }), (function() {})).completeBuild(); })) .onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(completedTodoCount(0), 0); }), (function() { var _ = Syndicate.__; return { assertion: completedTodoCount(0), metalevel: 0 }; }), (function() { -var _cachedAssertion1468253788491_4 = (function() { var _ = Syndicate.__; return completedTodoCount(0); })(); +var _cachedAssertion1468254188794_4 = (function() { var _ = Syndicate.__; return completedTodoCount(0); })(); Syndicate.Actor.createFacet() .addAssertion((function() { var _ = Syndicate.__; return Syndicate.Patch.assert(Syndicate.UI.uiAttribute('button.clear-completed', 'class', 'hidden'), 0); })) -.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468253788491_4, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468253788491_4, metalevel: 0 }; }), (function() {})).completeBuild(); })) +.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468254188794_4, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468254188794_4, metalevel: 0 }; }), (function() {})).completeBuild(); })) .onEvent(false, "message", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(Syndicate.UI.globalEvent('button.clear-completed', 'click', _), 0); }), (function() { var _ = Syndicate.__; return { assertion: Syndicate.UI.globalEvent('button.clear-completed', 'click', _), metalevel: 0 }; }), (function() { Syndicate.Dataspace.send(clearCompletedTodos()); })) .onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(allCompleted(), 0); }), (function() { var _ = Syndicate.__; return { assertion: allCompleted(), metalevel: 0 }; }), (function() { -var _cachedAssertion1468253788491_5 = (function() { var _ = Syndicate.__; return allCompleted(); })(); +var _cachedAssertion1468254188794_5 = (function() { var _ = Syndicate.__; return allCompleted(); })(); Syndicate.Actor.createFacet() .addInitBlock((function() { Syndicate.Dataspace.send(Syndicate.UI.setProperty('.toggle-all', 'checked', true)); })) .addDoneBlock((function() { Syndicate.Dataspace.send(Syndicate.UI.setProperty('.toggle-all', 'checked', false)); })) -.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468253788491_5, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468253788491_5, metalevel: 0 }; }), (function() {})).completeBuild(); })) +.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468254188794_5, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468254188794_5, metalevel: 0 }; }), (function() {})).completeBuild(); })) .onEvent(false, "message", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(Syndicate.UI.globalEvent('.toggle-all', 'change', _), 0); }), (function() { var _ = Syndicate.__; return { assertion: Syndicate.UI.globalEvent('.toggle-all', 'change', (Syndicate._$("e"))), metalevel: 0 }; }), (function(e) { Syndicate.Dataspace.send(setAllCompleted(e.target.checked)); })) @@ -169,27 +169,27 @@ Syndicate.Actor.createFacet() (function () { Syndicate.Actor.createFacet() .onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(Syndicate.UI.locationHash(_), 0); }), (function() { var _ = Syndicate.__; return { assertion: Syndicate.UI.locationHash((Syndicate._$("hash"))), metalevel: 0 }; }), (function(hash) { -var _cachedAssertion1468253788491_6 = (function() { var _ = Syndicate.__; return Syndicate.UI.locationHash(hash); })(); +var _cachedAssertion1468254188794_6 = (function() { var _ = Syndicate.__; return Syndicate.UI.locationHash(hash); })(); Syndicate.Actor.createFacet() .addAssertion((function() { var _ = Syndicate.__; return Syndicate.Patch.assert(Syndicate.UI.uiAttribute('ul.filters > li > a[href="#'+hash+'"]', 'class', 'selected'), 0); })) -.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468253788491_6, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468253788491_6, metalevel: 0 }; }), (function() {})).completeBuild(); })) +.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468254188794_6, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468254188794_6, metalevel: 0 }; }), (function() {})).completeBuild(); })) .onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(Syndicate.UI.locationHash('/'), 0); }), (function() { var _ = Syndicate.__; return { assertion: Syndicate.UI.locationHash('/'), metalevel: 0 }; }), (function() { -var _cachedAssertion1468253788491_7 = (function() { var _ = Syndicate.__; return Syndicate.UI.locationHash('/'); })(); +var _cachedAssertion1468254188794_7 = (function() { var _ = Syndicate.__; return Syndicate.UI.locationHash('/'); })(); Syndicate.Actor.createFacet() .addAssertion((function() { var _ = Syndicate.__; return Syndicate.Patch.assert(show(true), 0); })) .addAssertion((function() { var _ = Syndicate.__; return Syndicate.Patch.assert(show(false), 0); })) -.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468253788491_7, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468253788491_7, metalevel: 0 }; }), (function() {})).completeBuild(); })) +.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468254188794_7, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468254188794_7, metalevel: 0 }; }), (function() {})).completeBuild(); })) .onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(Syndicate.UI.locationHash('/active'), 0); }), (function() { var _ = Syndicate.__; return { assertion: Syndicate.UI.locationHash('/active'), metalevel: 0 }; }), (function() { -var _cachedAssertion1468253788491_8 = (function() { var _ = Syndicate.__; return Syndicate.UI.locationHash('/active'); })(); +var _cachedAssertion1468254188794_8 = (function() { var _ = Syndicate.__; return Syndicate.UI.locationHash('/active'); })(); Syndicate.Actor.createFacet() .addAssertion((function() { var _ = Syndicate.__; return Syndicate.Patch.assert(show(false), 0); })) -.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468253788491_8, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468253788491_8, metalevel: 0 }; }), (function() {})).completeBuild(); })) +.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468254188794_8, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468254188794_8, metalevel: 0 }; }), (function() {})).completeBuild(); })) .onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(Syndicate.UI.locationHash('/completed'), 0); }), (function() { var _ = Syndicate.__; return { assertion: Syndicate.UI.locationHash('/completed'), metalevel: 0 }; }), (function() { -var _cachedAssertion1468253788491_9 = (function() { var _ = Syndicate.__; return Syndicate.UI.locationHash('/completed'); })(); +var _cachedAssertion1468254188794_9 = (function() { var _ = Syndicate.__; return Syndicate.UI.locationHash('/completed'); })(); Syndicate.Actor.createFacet() .addAssertion((function() { var _ = Syndicate.__; return Syndicate.Patch.assert(show(true), 0); })) -.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468253788491_9, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468253788491_9, metalevel: 0 }; }), (function() {})).completeBuild(); })).completeBuild(); })(); +.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468254188794_9, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468254188794_9, metalevel: 0 }; }), (function() {})).completeBuild(); })).completeBuild(); })(); }); Syndicate.Actor.spawnActor(new Object(), function() { @@ -218,20 +218,20 @@ Syndicate.Actor.createFacet() todoListItemModel(db.nextId++, title, false); })) .onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(todo(_, _, _), 0); }), (function() { var _ = Syndicate.__; return { assertion: todo((Syndicate._$("id")), _, _), metalevel: 0 }; }), (function(id) { -var _cachedAssertion1468253788491_10 = (function() { var _ = Syndicate.__; return todo(id, _, _); })(); +var _cachedAssertion1468254188794_10 = (function() { var _ = Syndicate.__; return todo(id, _, _); })(); Syndicate.Actor.createFacet() .onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(todo(id, _, _), 0); }), (function() { var _ = Syndicate.__; return { assertion: todo(id, (Syndicate._$("title")), (Syndicate._$("completed"))), metalevel: 0 }; }), (function(title, completed) { -var _cachedAssertion1468253788491_11 = (function() { var _ = Syndicate.__; return todo(id, title, completed); })(); +var _cachedAssertion1468254188794_11 = (function() { var _ = Syndicate.__; return todo(id, title, completed); })(); Syndicate.Actor.createFacet() .addInitBlock((function() { db.todos[id] = {id: id, title: title, completed: completed}; localStorage['todos-syndicate'] = JSON.stringify(db); })) -.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468253788491_11, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468253788491_11, metalevel: 0 }; }), (function() {})).completeBuild(); })) +.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468254188794_11, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468254188794_11, metalevel: 0 }; }), (function() {})).completeBuild(); })) .addDoneBlock((function() { delete db.todos[id]; localStorage['todos-syndicate'] = JSON.stringify(db); })) -.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468253788491_10, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468253788491_10, metalevel: 0 }; }), (function() {})).completeBuild(); })).completeBuild(); })(); +.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468254188794_10, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468254188794_10, metalevel: 0 }; }), (function() {})).completeBuild(); })).completeBuild(); })(); }); }).startStepping(); diff --git a/examples/two-buyer-protocol/index.expanded.js b/examples/two-buyer-protocol/index.expanded.js index e065f5c..1a615c9 100644 --- a/examples/two-buyer-protocol/index.expanded.js +++ b/examples/two-buyer-protocol/index.expanded.js @@ -24,73 +24,36 @@ var Syndicate = require('../../src/main.js'); /// ### Role: SELLER /// -/// - when interest in `bookQuote($title, _)` appears, -/// asserts `bookQuote(title, Maybe Float)`, `false` meaning not available, -/// and otherwise an asking-price. -/// - when interest in `order($title, $offer-price, _, _)` appears, -/// asserts `order(title, offer-price, false, false)` for "no sale", otherwise -/// `order(title, offer-price, PositiveInteger, String)`, an accepted sale. +/// When interest in `bookQuote($title, _)` appears, asserts +/// `bookQuote(title, Maybe Float)`, `false` meaning not available, +/// and otherwise an asking-price. +/// +/// When interest in `order($title, $offer-price, _, _)` appears, +/// asserts `order(title, offer-price, false, false)` for "no sale", +/// otherwise `order(title, offer-price, PositiveInteger, String)`, an +/// accepted sale. /// ### Role: BUYER /// -/// - observes `bookQuote(title, $price)` to learn prices. -/// - observes `order(title, offer-price, $id, $delivery-date)` to make orders. +/// Observes `bookQuote(title, $price)` to learn prices. +/// +/// Observes `order(title, offer-price, $id, $delivery-date)` to make orders. /// ### Role: SPLIT-PROPOSER /// -/// - observes `splitProposal(title, asking-price, contribution, $accepted)` -/// to make a split-proposal and learn whether it was accepted or not. +/// Observes `splitProposal(title, asking-price, contribution, +/// $accepted)` to make a split-proposal and learn whether it was +/// accepted or not. /// ### Role: SPLIT-DISPOSER /// -/// - when interest in `splitProposal($title, $asking-price, $contribution, _)` -/// appears, asserts `splitProposal(title, askingPrice, contribution, true)` -/// to indicate they are willing to go through with the deal, in which case -/// they then perform the role of BUYER for title/asking-price, or asserts -/// `splitProposal(title, asking-price, contribution, false)` to indicate they -/// are unwilling to go through with the deal. - -/// ## A Sample Run -/// -/// Run the program with `../../bin/syndicatec index.js | node` from a -/// checkout of the Syndicate repository. -/// -/// A learns that the price of Catch 22 is 2.22 -/// A makes an offer to split the price of Catch 22 contributing 1.11 -/// B is being asked to contribute 1.11 toward Catch 22 at price 2.22 -/// B accepts the offer, leaving them with 3.8899999999999997 remaining funds -/// A learns that the split-proposal for Catch 22 was accepted -/// A learns that Encyclopaedia Brittannica is out-of-stock. -/// The order for Catch 22 has id 10001483, and will be delivered on March 9th -/// A learns that the price of Candide is 34.95 -/// A makes an offer to split the price of Candide contributing 17.475 -/// B is being asked to contribute 17.475 toward Candide at price 34.95 -/// B hasn't enough funds (3.8899999999999997 remaining) -/// A learns that the split-proposal for Candide was rejected -/// A makes an offer to split the price of Candide contributing 26.212500000000002 -/// B is being asked to contribute 8.7375 toward Candide at price 34.95 -/// B hasn't enough funds (3.8899999999999997 remaining) -/// A learns that the split-proposal for Candide was rejected -/// A makes an offer to split the price of Candide contributing 30.581250000000004 -/// B is being asked to contribute 4.368749999999999 toward Candide at price 34.95 -/// B hasn't enough funds (3.8899999999999997 remaining) -/// A learns that the split-proposal for Candide was rejected -/// A makes an offer to split the price of Candide contributing 32.765625 -/// B is being asked to contribute 2.184375000000003 toward Candide at price 34.95 -/// B accepts the offer, leaving them with 1.7056249999999968 remaining funds -/// A learns that the split-proposal for Candide was accepted -/// A learns that the price of The Wind in the Willows is 3.95 -/// A makes an offer to split the price of The Wind in the Willows contributing 1.975 -/// The order for Candide has id 10001484, and will be delivered on March 9th -/// B is being asked to contribute 1.975 toward The Wind in the Willows at price 3.95 -/// B hasn't enough funds (1.7056249999999968 remaining) -/// A learns that the split-proposal for The Wind in the Willows was rejected -/// A makes an offer to split the price of The Wind in the Willows contributing 2.9625000000000004 -/// B is being asked to contribute 0.9874999999999998 toward The Wind in the Willows at price 3.95 -/// B accepts the offer, leaving them with 0.718124999999997 remaining funds -/// A learns that the split-proposal for The Wind in the Willows was accepted -/// A has bought everything they wanted! -/// The order for The Wind in the Willows has id 10001485, and will be delivered on March 9th +/// When interest in `splitProposal($title, $asking-price, +/// $contribution, _)` appears, asserts `splitProposal(title, +/// askingPrice, contribution, true)` to indicate they are willing to +/// go through with the deal, in which case they then perform the role +/// of BUYER for title/asking-price, or asserts `splitProposal(title, +/// asking-price, contribution, false)` to indicate they are unwilling +/// to go through with the deal. /// ## The Code @@ -144,10 +107,10 @@ function seller() { (function () { Syndicate.Actor.createFacet() .onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(Syndicate.observe(bookQuote(_, _)), 0); }), (function() { var _ = Syndicate.__; return { assertion: Syndicate.observe(bookQuote((Syndicate._$("title")), _)), metalevel: 0 }; }), (function(title) { -var _cachedAssertion1468253789712_0 = (function() { var _ = Syndicate.__; return Syndicate.observe(bookQuote(title, _)); })(); +var _cachedAssertion1468254190138_0 = (function() { var _ = Syndicate.__; return Syndicate.observe(bookQuote(title, _)); })(); Syndicate.Actor.createFacet() .addAssertion((function() { var _ = Syndicate.__; return Syndicate.Patch.assert(bookQuote(title, this.priceOf(title)), 0); })) -.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468253789712_0, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468253789712_0, metalevel: 0 }; }), (function() {})).completeBuild(); })).completeBuild(); })(); +.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(_cachedAssertion1468254190138_0, 0); }), (function() { var _ = Syndicate.__; return { assertion: _cachedAssertion1468254190138_0, metalevel: 0 }; }), (function() {})).completeBuild(); })).completeBuild(); })(); /// It also responds to order requests. @@ -248,17 +211,17 @@ Syndicate.Actor.createFacet() (function () { Syndicate.Actor.createFacet() .onEvent(true, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(splitProposal(title, price, contribution, true), 0); }), (function() { var _ = Syndicate.__; return { assertion: splitProposal(title, price, contribution, true), metalevel: 0 }; }), (function() { - console.log("A learns that the split-proposal for "+ - title+" was accepted"); - buyBooks(); - })) + console.log("A learns that the split-proposal for "+ + title+" was accepted"); + buyBooks(); + })) .onEvent(true, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(splitProposal(title, price, contribution, false), 0); }), (function() { var _ = Syndicate.__; return { assertion: splitProposal(title, price, contribution, false), metalevel: 0 }; }), (function() { - console.log("A learns that the split-proposal for "+ - title+" was rejected"); - trySplit(title, - price, - contribution + ((price - contribution) / 2)); - })).completeBuild(); })(); + console.log("A learns that the split-proposal for "+ + title+" was rejected"); + trySplit(title, + price, + contribution + ((price - contribution) / 2)); + })).completeBuild(); })(); } } }); diff --git a/examples/two-buyer-protocol/index.js b/examples/two-buyer-protocol/index.js index 8844989..2bb45fc 100644 --- a/examples/two-buyer-protocol/index.js +++ b/examples/two-buyer-protocol/index.js @@ -28,73 +28,36 @@ var Syndicate = require('../../src/main.js'); /// ### Role: SELLER /// -/// - when interest in `bookQuote($title, _)` appears, -/// asserts `bookQuote(title, Maybe Float)`, `false` meaning not available, -/// and otherwise an asking-price. -/// - when interest in `order($title, $offer-price, _, _)` appears, -/// asserts `order(title, offer-price, false, false)` for "no sale", otherwise -/// `order(title, offer-price, PositiveInteger, String)`, an accepted sale. +/// When interest in `bookQuote($title, _)` appears, asserts +/// `bookQuote(title, Maybe Float)`, `false` meaning not available, +/// and otherwise an asking-price. +/// +/// When interest in `order($title, $offer-price, _, _)` appears, +/// asserts `order(title, offer-price, false, false)` for "no sale", +/// otherwise `order(title, offer-price, PositiveInteger, String)`, an +/// accepted sale. /// ### Role: BUYER /// -/// - observes `bookQuote(title, $price)` to learn prices. -/// - observes `order(title, offer-price, $id, $delivery-date)` to make orders. +/// Observes `bookQuote(title, $price)` to learn prices. +/// +/// Observes `order(title, offer-price, $id, $delivery-date)` to make orders. /// ### Role: SPLIT-PROPOSER /// -/// - observes `splitProposal(title, asking-price, contribution, $accepted)` -/// to make a split-proposal and learn whether it was accepted or not. +/// Observes `splitProposal(title, asking-price, contribution, +/// $accepted)` to make a split-proposal and learn whether it was +/// accepted or not. /// ### Role: SPLIT-DISPOSER /// -/// - when interest in `splitProposal($title, $asking-price, $contribution, _)` -/// appears, asserts `splitProposal(title, askingPrice, contribution, true)` -/// to indicate they are willing to go through with the deal, in which case -/// they then perform the role of BUYER for title/asking-price, or asserts -/// `splitProposal(title, asking-price, contribution, false)` to indicate they -/// are unwilling to go through with the deal. - -/// ## A Sample Run -/// -/// Run the program with `../../bin/syndicatec index.js | node` from a -/// checkout of the Syndicate repository. -/// -/// A learns that the price of Catch 22 is 2.22 -/// A makes an offer to split the price of Catch 22 contributing 1.11 -/// B is being asked to contribute 1.11 toward Catch 22 at price 2.22 -/// B accepts the offer, leaving them with 3.8899999999999997 remaining funds -/// A learns that the split-proposal for Catch 22 was accepted -/// A learns that Encyclopaedia Brittannica is out-of-stock. -/// The order for Catch 22 has id 10001483, and will be delivered on March 9th -/// A learns that the price of Candide is 34.95 -/// A makes an offer to split the price of Candide contributing 17.475 -/// B is being asked to contribute 17.475 toward Candide at price 34.95 -/// B hasn't enough funds (3.8899999999999997 remaining) -/// A learns that the split-proposal for Candide was rejected -/// A makes an offer to split the price of Candide contributing 26.212500000000002 -/// B is being asked to contribute 8.7375 toward Candide at price 34.95 -/// B hasn't enough funds (3.8899999999999997 remaining) -/// A learns that the split-proposal for Candide was rejected -/// A makes an offer to split the price of Candide contributing 30.581250000000004 -/// B is being asked to contribute 4.368749999999999 toward Candide at price 34.95 -/// B hasn't enough funds (3.8899999999999997 remaining) -/// A learns that the split-proposal for Candide was rejected -/// A makes an offer to split the price of Candide contributing 32.765625 -/// B is being asked to contribute 2.184375000000003 toward Candide at price 34.95 -/// B accepts the offer, leaving them with 1.7056249999999968 remaining funds -/// A learns that the split-proposal for Candide was accepted -/// A learns that the price of The Wind in the Willows is 3.95 -/// A makes an offer to split the price of The Wind in the Willows contributing 1.975 -/// The order for Candide has id 10001484, and will be delivered on March 9th -/// B is being asked to contribute 1.975 toward The Wind in the Willows at price 3.95 -/// B hasn't enough funds (1.7056249999999968 remaining) -/// A learns that the split-proposal for The Wind in the Willows was rejected -/// A makes an offer to split the price of The Wind in the Willows contributing 2.9625000000000004 -/// B is being asked to contribute 0.9874999999999998 toward The Wind in the Willows at price 3.95 -/// B accepts the offer, leaving them with 0.718124999999997 remaining funds -/// A learns that the split-proposal for The Wind in the Willows was accepted -/// A has bought everything they wanted! -/// The order for The Wind in the Willows has id 10001485, and will be delivered on March 9th +/// When interest in `splitProposal($title, $asking-price, +/// $contribution, _)` appears, asserts `splitProposal(title, +/// askingPrice, contribution, true)` to indicate they are willing to +/// go through with the deal, in which case they then perform the role +/// of BUYER for title/asking-price, or asserts `splitProposal(title, +/// asking-price, contribution, false)` to indicate they are unwilling +/// to go through with the deal. /// ## The Code @@ -156,8 +119,7 @@ function seller() { react { on asserted - Syndicate.observe(order($title, $offerPrice, _, _)) - { + Syndicate.observe(order($title, $offerPrice, _, _)) { /// We cannot sell a book we do not have, and we will not sell for /// less than our asking price. @@ -252,22 +214,20 @@ function buyerA() { react until { case asserted - splitProposal(title, price, contribution, true) - { - console.log("A learns that the split-proposal for "+ - title+" was accepted"); - buyBooks(); - } + splitProposal(title, price, contribution, true) { + console.log("A learns that the split-proposal for "+ + title+" was accepted"); + buyBooks(); + } case asserted - splitProposal(title, price, contribution, false) - { - console.log("A learns that the split-proposal for "+ - title+" was rejected"); - trySplit(title, - price, - contribution + ((price - contribution) / 2)); - } + splitProposal(title, price, contribution, false) { + console.log("A learns that the split-proposal for "+ + title+" was rejected"); + trySplit(title, + price, + contribution + ((price - contribution) / 2)); + } } } } @@ -349,3 +309,45 @@ ground dataspace { buyerA(); buyerB(); } + +/// ## A Sample Run +/// +/// Run the program with `../../bin/syndicatec index.js | node` from a +/// checkout of the Syndicate repository. +/// +/// A learns that the price of Catch 22 is 2.22 +/// A makes an offer to split the price of Catch 22 contributing 1.11 +/// B is being asked to contribute 1.11 toward Catch 22 at price 2.22 +/// B accepts the offer, leaving them with 3.8899999999999997 remaining funds +/// A learns that the split-proposal for Catch 22 was accepted +/// A learns that Encyclopaedia Brittannica is out-of-stock. +/// The order for Catch 22 has id 10001483, and will be delivered on March 9th +/// A learns that the price of Candide is 34.95 +/// A makes an offer to split the price of Candide contributing 17.475 +/// B is being asked to contribute 17.475 toward Candide at price 34.95 +/// B hasn't enough funds (3.8899999999999997 remaining) +/// A learns that the split-proposal for Candide was rejected +/// A makes an offer to split the price of Candide contributing 26.212500000000002 +/// B is being asked to contribute 8.7375 toward Candide at price 34.95 +/// B hasn't enough funds (3.8899999999999997 remaining) +/// A learns that the split-proposal for Candide was rejected +/// A makes an offer to split the price of Candide contributing 30.581250000000004 +/// B is being asked to contribute 4.368749999999999 toward Candide at price 34.95 +/// B hasn't enough funds (3.8899999999999997 remaining) +/// A learns that the split-proposal for Candide was rejected +/// A makes an offer to split the price of Candide contributing 32.765625 +/// B is being asked to contribute 2.184375000000003 toward Candide at price 34.95 +/// B accepts the offer, leaving them with 1.7056249999999968 remaining funds +/// A learns that the split-proposal for Candide was accepted +/// A learns that the price of The Wind in the Willows is 3.95 +/// A makes an offer to split the price of The Wind in the Willows contributing 1.975 +/// The order for Candide has id 10001484, and will be delivered on March 9th +/// B is being asked to contribute 1.975 toward The Wind in the Willows at price 3.95 +/// B hasn't enough funds (1.7056249999999968 remaining) +/// A learns that the split-proposal for The Wind in the Willows was rejected +/// A makes an offer to split the price of The Wind in the Willows contributing 2.9625000000000004 +/// B is being asked to contribute 0.9874999999999998 toward The Wind in the Willows at price 3.95 +/// B accepts the offer, leaving them with 0.718124999999997 remaining funds +/// A learns that the split-proposal for The Wind in the Willows was accepted +/// A has bought everything they wanted! +/// The order for The Wind in the Willows has id 10001485, and will be delivered on March 9th diff --git a/examples/two-buyer-protocol/index.md b/examples/two-buyer-protocol/index.md index c9d7c7c..96a1ec6 100644 --- a/examples/two-buyer-protocol/index.md +++ b/examples/two-buyer-protocol/index.md @@ -28,73 +28,36 @@ negotiates the purchase of the book with the book-seller. ### Role: SELLER - - when interest in `bookQuote($title, _)` appears, - asserts `bookQuote(title, Maybe Float)`, `false` meaning not available, - and otherwise an asking-price. - - when interest in `order($title, $offer-price, _, _)` appears, - asserts `order(title, offer-price, false, false)` for "no sale", otherwise - `order(title, offer-price, PositiveInteger, String)`, an accepted sale. +When interest in `bookQuote($title, _)` appears, asserts +`bookQuote(title, Maybe Float)`, `false` meaning not available, +and otherwise an asking-price. + +When interest in `order($title, $offer-price, _, _)` appears, +asserts `order(title, offer-price, false, false)` for "no sale", +otherwise `order(title, offer-price, PositiveInteger, String)`, an +accepted sale. ### Role: BUYER - - observes `bookQuote(title, $price)` to learn prices. - - observes `order(title, offer-price, $id, $delivery-date)` to make orders. +Observes `bookQuote(title, $price)` to learn prices. + +Observes `order(title, offer-price, $id, $delivery-date)` to make orders. ### Role: SPLIT-PROPOSER - - observes `splitProposal(title, asking-price, contribution, $accepted)` - to make a split-proposal and learn whether it was accepted or not. +Observes `splitProposal(title, asking-price, contribution, +$accepted)` to make a split-proposal and learn whether it was +accepted or not. ### Role: SPLIT-DISPOSER - - when interest in `splitProposal($title, $asking-price, $contribution, _)` - appears, asserts `splitProposal(title, askingPrice, contribution, true)` - to indicate they are willing to go through with the deal, in which case - they then perform the role of BUYER for title/asking-price, or asserts - `splitProposal(title, asking-price, contribution, false)` to indicate they - are unwilling to go through with the deal. - -## A Sample Run - -Run the program with `../../bin/syndicatec index.js | node` from a -checkout of the Syndicate repository. - - A learns that the price of Catch 22 is 2.22 - A makes an offer to split the price of Catch 22 contributing 1.11 - B is being asked to contribute 1.11 toward Catch 22 at price 2.22 - B accepts the offer, leaving them with 3.8899999999999997 remaining funds - A learns that the split-proposal for Catch 22 was accepted - A learns that Encyclopaedia Brittannica is out-of-stock. - The order for Catch 22 has id 10001483, and will be delivered on March 9th - A learns that the price of Candide is 34.95 - A makes an offer to split the price of Candide contributing 17.475 - B is being asked to contribute 17.475 toward Candide at price 34.95 - B hasn't enough funds (3.8899999999999997 remaining) - A learns that the split-proposal for Candide was rejected - A makes an offer to split the price of Candide contributing 26.212500000000002 - B is being asked to contribute 8.7375 toward Candide at price 34.95 - B hasn't enough funds (3.8899999999999997 remaining) - A learns that the split-proposal for Candide was rejected - A makes an offer to split the price of Candide contributing 30.581250000000004 - B is being asked to contribute 4.368749999999999 toward Candide at price 34.95 - B hasn't enough funds (3.8899999999999997 remaining) - A learns that the split-proposal for Candide was rejected - A makes an offer to split the price of Candide contributing 32.765625 - B is being asked to contribute 2.184375000000003 toward Candide at price 34.95 - B accepts the offer, leaving them with 1.7056249999999968 remaining funds - A learns that the split-proposal for Candide was accepted - A learns that the price of The Wind in the Willows is 3.95 - A makes an offer to split the price of The Wind in the Willows contributing 1.975 - The order for Candide has id 10001484, and will be delivered on March 9th - B is being asked to contribute 1.975 toward The Wind in the Willows at price 3.95 - B hasn't enough funds (1.7056249999999968 remaining) - A learns that the split-proposal for The Wind in the Willows was rejected - A makes an offer to split the price of The Wind in the Willows contributing 2.9625000000000004 - B is being asked to contribute 0.9874999999999998 toward The Wind in the Willows at price 3.95 - B accepts the offer, leaving them with 0.718124999999997 remaining funds - A learns that the split-proposal for The Wind in the Willows was accepted - A has bought everything they wanted! - The order for The Wind in the Willows has id 10001485, and will be delivered on March 9th +When interest in `splitProposal($title, $asking-price, +$contribution, _)` appears, asserts `splitProposal(title, +askingPrice, contribution, true)` to indicate they are willing to +go through with the deal, in which case they then perform the role +of BUYER for title/asking-price, or asserts `splitProposal(title, +asking-price, contribution, false)` to indicate they are unwilling +to go through with the deal. ## The Code @@ -156,8 +119,7 @@ It also responds to order requests. react { on asserted - Syndicate.observe(order($title, $offerPrice, _, _)) - { + Syndicate.observe(order($title, $offerPrice, _, _)) { We cannot sell a book we do not have, and we will not sell for less than our asking price. @@ -252,22 +214,20 @@ Make our proposal, and wait for a response. react until { case asserted - splitProposal(title, price, contribution, true) - { - console.log("A learns that the split-proposal for "+ - title+" was accepted"); - buyBooks(); - } + splitProposal(title, price, contribution, true) { + console.log("A learns that the split-proposal for "+ + title+" was accepted"); + buyBooks(); + } case asserted - splitProposal(title, price, contribution, false) - { - console.log("A learns that the split-proposal for "+ - title+" was rejected"); - trySplit(title, - price, - contribution + ((price - contribution) / 2)); - } + splitProposal(title, price, contribution, false) { + console.log("A learns that the split-proposal for "+ + title+" was rejected"); + trySplit(title, + price, + contribution + ((price - contribution) / 2)); + } } } } @@ -349,3 +309,45 @@ When order confirmation arrives, this purchase is completed. buyerA(); buyerB(); } + +## A Sample Run + +Run the program with `../../bin/syndicatec index.js | node` from a +checkout of the Syndicate repository. + + A learns that the price of Catch 22 is 2.22 + A makes an offer to split the price of Catch 22 contributing 1.11 + B is being asked to contribute 1.11 toward Catch 22 at price 2.22 + B accepts the offer, leaving them with 3.8899999999999997 remaining funds + A learns that the split-proposal for Catch 22 was accepted + A learns that Encyclopaedia Brittannica is out-of-stock. + The order for Catch 22 has id 10001483, and will be delivered on March 9th + A learns that the price of Candide is 34.95 + A makes an offer to split the price of Candide contributing 17.475 + B is being asked to contribute 17.475 toward Candide at price 34.95 + B hasn't enough funds (3.8899999999999997 remaining) + A learns that the split-proposal for Candide was rejected + A makes an offer to split the price of Candide contributing 26.212500000000002 + B is being asked to contribute 8.7375 toward Candide at price 34.95 + B hasn't enough funds (3.8899999999999997 remaining) + A learns that the split-proposal for Candide was rejected + A makes an offer to split the price of Candide contributing 30.581250000000004 + B is being asked to contribute 4.368749999999999 toward Candide at price 34.95 + B hasn't enough funds (3.8899999999999997 remaining) + A learns that the split-proposal for Candide was rejected + A makes an offer to split the price of Candide contributing 32.765625 + B is being asked to contribute 2.184375000000003 toward Candide at price 34.95 + B accepts the offer, leaving them with 1.7056249999999968 remaining funds + A learns that the split-proposal for Candide was accepted + A learns that the price of The Wind in the Willows is 3.95 + A makes an offer to split the price of The Wind in the Willows contributing 1.975 + The order for Candide has id 10001484, and will be delivered on March 9th + B is being asked to contribute 1.975 toward The Wind in the Willows at price 3.95 + B hasn't enough funds (1.7056249999999968 remaining) + A learns that the split-proposal for The Wind in the Willows was rejected + A makes an offer to split the price of The Wind in the Willows contributing 2.9625000000000004 + B is being asked to contribute 0.9874999999999998 toward The Wind in the Willows at price 3.95 + B accepts the offer, leaving them with 0.718124999999997 remaining funds + A learns that the split-proposal for The Wind in the Willows was accepted + A has bought everything they wanted! + The order for The Wind in the Willows has id 10001485, and will be delivered on March 9th