Seal DOMFragment specifications.

This commit is contained in:
Tony Garnock-Jones 2016-02-06 15:06:59 -05:00
parent afa657096a
commit 6d028f00c5
4 changed files with 20 additions and 5 deletions

View File

@ -4,6 +4,7 @@ $(document).ready(function () {
var sub = Syndicate.sub;
var assert = Syndicate.assert;
var retract = Syndicate.retract;
var seal = Syndicate.seal;
var __ = Syndicate.__;
var _$ = Syndicate._$;
@ -15,7 +16,7 @@ $(document).ready(function () {
Network.spawn({
boot: function () {
return assert(["DOM", "#clicker-holder", "clicker",
["button", ["span", [["style", "font-style: italic"]], "Click me!"]]])
seal(["button", ["span", [["style", "font-style: italic"]], "Click me!"]])])
.andThen(sub(["jQuery", "button.clicker", "click", __]));
},
handleEvent: function (e) {
@ -34,8 +35,9 @@ $(document).ready(function () {
updateState: function () {
Network.stateChange(retract(["DOM", __, __, __])
.andThen(assert(["DOM", "#counter-holder", "counter",
["div",
["p", "The current count is: ", this.counter]]])));
seal(["div",
["p", "The current count is: ",
this.counter]])])));
},
handleEvent: function (e) {
if (e.type === "message" && e.message === "bump_count") {

View File

@ -2,6 +2,7 @@
var Syndicate = require("./syndicate.js");
var Patch = require("./patch.js");
var DemandMatcher = require('./demand-matcher.js').DemandMatcher;
var Seal = require('./seal.js').Seal;
var Network = Syndicate.Network;
var __ = Syndicate.__;
var _$ = Syndicate._$;
@ -122,7 +123,7 @@ DOMFragment.prototype.buildNodes = function () {
var self = this;
var nodes = [];
$(self.selector).each(function (index, domNode) {
var n = self.interpretSpec(self.fragmentSpec.toJS());
var n = self.interpretSpec(self.fragmentSpec.sealContents);
n.classList.add(self.fragmentClass);
domNode.appendChild(n);
nodes.push(n);

View File

@ -17,8 +17,12 @@ copyKeys(['__', '_$', '$Capture', '$Special',
module.exports,
module.exports.Route);
var Seal = require('./seal.js')
copyKeys(['Seal', 'seal'],
module.exports,
Seal);
module.exports.DemandMatcher = require('./demand-matcher.js').DemandMatcher;
module.exports.Seal = require('./seal.js').Seal;
module.exports.Ack = require('./ack.js').Ack;
module.exports.RandomID = require('./randomid.js');

View File

@ -1,5 +1,8 @@
var Immutable = require('immutable');
function Seal(contents) {
this.sealContents = contents;
Object.freeze(this);
}
Seal.prototype.equals = function (other) {
@ -7,4 +10,9 @@ Seal.prototype.equals = function (other) {
return Immutable.is(this.sealContents, other.sealContents);
};
function seal(contents) {
return new Seal(contents);
}
module.exports.Seal = Seal;
module.exports.seal = seal;