Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tagged 0.4.1

  • Loading branch information...
commit 449c8de2d1fa9cdd07446ee0eab93fd0acd1ce8b 1 parent 15e0365
Jonas Nicklas and Kim Burgestrand authored
View
563 lib/assets/javascripts/serenade.js
@@ -1,6 +1,6 @@
/**
- * Serenade.js JavaScript Framework v0.4.0
- * Revision: 5301262146
+ * Serenade.js JavaScript Framework v0.4.1
+ * Revision: ae7d321b18
* http://github.com/elabs/serenade.js
*
* Copyright 2011, Jonas Nicklas, Elabs AB
@@ -11,9 +11,9 @@
var parser = (function(){
var parser = {trace: function trace() { },
yy: {},
-symbols_: {"error":2,"Root":3,"Element":4,"ElementIdentifier":5,"AnyIdentifier":6,"#":7,".":8,"[":9,"]":10,"PropertyList":11,"WHITESPACE":12,"Text":13,"INDENT":14,"ChildList":15,"OUTDENT":16,"TextList":17,"Bound":18,"STRING_LITERAL":19,"Child":20,"TERMINATOR":21,"IfInstruction":22,"Instruction":23,"Helper":24,"Property":25,"=":26,"!":27,":":28,"-":29,"VIEW":30,"COLLECTION":31,"UNLESS":32,"IN":33,"IDENTIFIER":34,"IF":35,"ElseInstruction":36,"ELSE":37,"@":38,"$accept":0,"$end":1},
-terminals_: {2:"error",7:"#",8:".",9:"[",10:"]",12:"WHITESPACE",14:"INDENT",16:"OUTDENT",19:"STRING_LITERAL",21:"TERMINATOR",26:"=",27:"!",28:":",29:"-",30:"VIEW",31:"COLLECTION",32:"UNLESS",33:"IN",34:"IDENTIFIER",35:"IF",37:"ELSE",38:"@"},
-productions_: [0,[3,0],[3,1],[5,1],[5,3],[5,2],[5,2],[5,3],[4,1],[4,3],[4,4],[4,3],[4,4],[17,1],[17,3],[13,1],[13,1],[15,1],[15,3],[20,1],[20,1],[20,1],[20,1],[20,1],[11,1],[11,3],[25,3],[25,3],[25,4],[25,4],[25,3],[25,3],[23,5],[23,5],[23,5],[23,5],[23,4],[24,3],[24,3],[24,4],[22,5],[22,4],[22,2],[36,6],[6,1],[6,1],[6,1],[6,1],[6,1],[6,1],[18,2],[18,1]],
+symbols_: {"error":2,"Root":3,"ChildList":4,"ElementIdentifier":5,"AnyIdentifier":6,"#":7,".":8,"Element":9,"[":10,"]":11,"PropertyList":12,"WHITESPACE":13,"Text":14,"INDENT":15,"OUTDENT":16,"TextList":17,"Bound":18,"STRING_LITERAL":19,"Child":20,"TERMINATOR":21,"IfInstruction":22,"Instruction":23,"Helper":24,"Property":25,"=":26,"!":27,":":28,"-":29,"VIEW":30,"COLLECTION":31,"UNLESS":32,"IN":33,"IDENTIFIER":34,"IF":35,"ElseInstruction":36,"ELSE":37,"@":38,"$accept":0,"$end":1},
+terminals_: {2:"error",7:"#",8:".",10:"[",11:"]",13:"WHITESPACE",15:"INDENT",16:"OUTDENT",19:"STRING_LITERAL",21:"TERMINATOR",26:"=",27:"!",28:":",29:"-",30:"VIEW",31:"COLLECTION",32:"UNLESS",33:"IN",34:"IDENTIFIER",35:"IF",37:"ELSE",38:"@"},
+productions_: [0,[3,0],[3,1],[5,1],[5,3],[5,2],[5,2],[5,3],[9,1],[9,3],[9,4],[9,3],[9,4],[17,1],[17,3],[14,1],[14,1],[4,1],[4,3],[20,1],[20,1],[20,1],[20,1],[20,1],[12,1],[12,3],[25,3],[25,3],[25,4],[25,4],[25,3],[25,3],[23,5],[23,5],[23,5],[23,5],[23,4],[24,3],[24,3],[24,4],[22,5],[22,4],[22,2],[36,6],[6,1],[6,1],[6,1],[6,1],[6,1],[6,1],[18,2],[18,1]],
performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
var $0 = $$.length - 1;
@@ -237,7 +237,7 @@ case 51:this.$ = (function () {}());
break;
}
},
-table: [{1:[2,1],3:1,4:2,5:3,6:4,7:[1,5],8:[1,6],30:[1,7],31:[1,8],32:[1,10],33:[1,11],34:[1,12],35:[1,9]},{1:[3]},{1:[2,2],9:[1,13],12:[1,14],14:[1,15]},{1:[2,8],8:[1,16],9:[2,8],12:[2,8],14:[2,8],16:[2,8],21:[2,8]},{1:[2,3],7:[1,17],8:[2,3],9:[2,3],12:[2,3],14:[2,3],16:[2,3],21:[2,3]},{6:18,30:[1,7],31:[1,8],32:[1,10],33:[1,11],34:[1,12],35:[1,9]},{6:19,30:[1,7],31:[1,8],32:[1,10],33:[1,11],34:[1,12],35:[1,9]},{1:[2,44],7:[2,44],8:[2,44],9:[2,44],10:[2,44],12:[2,44],14:[2,44],16:[2,44],21:[2,44],26:[2,44],27:[2,44],28:[2,44],29:[2,44]},{1:[2,45],7:[2,45],8:[2,45],9:[2,45],10:[2,45],12:[2,45],14:[2,45],16:[2,45],21:[2,45],26:[2,45],27:[2,45],28:[2,45],29:[2,45]},{1:[2,46],7:[2,46],8:[2,46],9:[2,46],10:[2,46],12:[2,46],14:[2,46],16:[2,46],21:[2,46],26:[2,46],27:[2,46],28:[2,46],29:[2,46]},{1:[2,47],7:[2,47],8:[2,47],9:[2,47],10:[2,47],12:[2,47],14:[2,47],16:[2,47],21:[2,47],26:[2,47],27:[2,47],28:[2,47],29:[2,47]},{1:[2,48],7:[2,48],8:[2,48],9:[2,48],10:[2,48],12:[2,48],14:[2,48],16:[2,48],21:[2,48],26:[2,48],27:[2,48],28:[2,48],29:[2,48]},{1:[2,49],7:[2,49],8:[2,49],9:[2,49],10:[2,49],12:[2,49],14:[2,49],16:[2,49],21:[2,49],26:[2,49],27:[2,49],28:[2,49],29:[2,49]},{6:23,10:[1,20],11:21,25:22,30:[1,7],31:[1,8],32:[1,10],33:[1,11],34:[1,12],35:[1,9]},{13:24,18:25,19:[1,26],38:[1,27]},{4:30,5:3,6:4,7:[1,5],8:[1,6],13:36,15:28,17:34,18:25,19:[1,26],20:29,22:31,23:32,24:33,29:[1,35],30:[1,7],31:[1,8],32:[1,10],33:[1,11],34:[1,12],35:[1,9],38:[1,27]},{6:37,30:[1,7],31:[1,8],32:[1,10],33:[1,11],34:[1,12],35:[1,9]},{6:38,30:[1,7],31:[1,8],32:[1,10],33:[1,11],34:[1,12],35:[1,9]},{1:[2,5],8:[2,5],9:[2,5],12:[2,5],14:[2,5],16:[2,5],21:[2,5]},{1:[2,6],8:[2,6],9:[2,6],12:[2,6],14:[2,6],16:[2,6],21:[2,6]},{1:[2,9],9:[2,9],12:[2,9],14:[2,9],16:[2,9],21:[2,9]},{10:[1,39],12:[1,40]},{10:[2,24],12:[2,24]},{26:[1,41],28:[1,42]},{1:[2,11],9:[2,11],12:[2,11],14:[2,11],16:[2,11],21:[2,11]},{1:[2,15],9:[2,15],12:[2,15],14:[2,15],16:[2,15],21:[2,15]},{1:[2,16],9:[2,16],12:[2,16],14:[2,16],16:[2,16],21:[2,16]},{1:[2,51],6:43,9:[2,51],10:[2,51],12:[2,51],14:[2,51],16:[2,51],21:[2,51],27:[2,51],29:[2,51],30:[1,7],31:[1,8],32:[1,10],33:[1,11],34:[1,12],35:[1,9]},{16:[1,44],21:[1,45]},{16:[2,17],21:[2,17]},{9:[1,13],12:[1,14],14:[1,15],16:[2,19],21:[2,19]},{14:[1,46],16:[2,20],21:[2,20],29:[1,48],36:47},{14:[1,49],16:[2,21],21:[2,21]},{12:[1,50],14:[1,51],16:[2,22],21:[2,22]},{12:[1,52],16:[2,23],21:[2,23]},{12:[1,53]},{12:[2,13],16:[2,13],21:[2,13]},{1:[2,7],8:[2,7],9:[2,7],12:[2,7],14:[2,7],16:[2,7],21:[2,7]},{1:[2,4],8:[2,4],9:[2,4],12:[2,4],14:[2,4],16:[2,4],21:[2,4]},{1:[2,10],9:[2,10],12:[2,10],14:[2,10],16:[2,10],21:[2,10]},{6:23,25:54,30:[1,7],31:[1,8],32:[1,10],33:[1,11],34:[1,12],35:[1,9]},{6:55,18:56,19:[1,57],30:[1,7],31:[1,8],32:[1,10],33:[1,11],34:[1,12],35:[1,9],38:[1,27]},{6:23,25:58,30:[1,7],31:[1,8],32:[1,10],33:[1,11],34:[1,12],35:[1,9]},{1:[2,50],9:[2,50],10:[2,50],12:[2,50],14:[2,50],16:[2,50],21:[2,50],27:[2,50],29:[2,50]},{1:[2,12],9:[2,12],12:[2,12],14:[2,12],16:[2,12],21:[2,12]},{4:30,5:3,6:4,7:[1,5],8:[1,6],13:36,17:34,18:25,19:[1,26],20:59,22:31,23:32,24:33,29:[1,35],30:[1,7],31:[1,8],32:[1,10],33:[1,11],34:[1,12],35:[1,9],38:[1,27]},{4:30,5:3,6:4,7:[1,5],8:[1,6],13:36,15:60,17:34,18:25,19:[1,26],20:29,22:31,23:32,24:33,29:[1,35],30:[1,7],31:[1,8],32:[1,10],33:[1,11],34:[1,12],35:[1,9],38:[1,27]},{14:[2,42],16:[2,42],21:[2,42],29:[2,42]},{12:[1,61]},{4:30,5:3,6:4,7:[1,5],8:[1,6],13:36,15:62,17:34,18:25,19:[1,26],20:29,22:31,23:32,24:33,29:[1,35],30:[1,7],31:[1,8],32:[1,10],33:[1,11],34:[1,12],35:[1,9],38:[1,27]},{13:63,18:25,19:[1,26],38:[1,27]},{4:30,5:3,6:4,7:[1,5],8:[1,6],13:36,15:64,17:34,18:25,19:[1,26],20:29,22:31,23:32,24:33,29:[1,35],30:[1,7],31:[1,8],32:[1,10],33:[1,11],34:[1,12],35:[1,9],38:[1,27]},{13:65,18:25,19:[1,26],38:[1,27]},{30:[1,67],31:[1,68],32:[1,69],33:[1,70],34:[1,71],35:[1,66]},{10:[2,25],12:[2,25]},{10:[2,26],12:[2,26],27:[1,72]},{10:[2,27],12:[2,27],27:[1,73]},{10:[2,30],12:[2,30]},{10:[2,31],12:[2,31]},{16:[2,18],21:[2,18]},{16:[1,74],21:[1,45]},{37:[1,75]},{16:[1,76],21:[1,45]},{12:[2,38],14:[2,38],16:[2,38],21:[2,38]},{16:[1,77],21:[1,45]},{12:[2,14],16:[2,14],21:[2,14]},{12:[1,78]},{12:[1,79]},{12:[1,80]},{12:[1,81]},{12:[1,82]},{12:[2,37],14:[2,37],16:[2,37],21:[2,37]},{10:[2,28],12:[2,28]},{10:[2,29],12:[2,29]},{14:[2,41],16:[2,41],21:[2,41],29:[2,41]},{14:[1,83]},{14:[2,36],16:[2,36],21:[2,36]},{12:[2,39],14:[2,39],16:[2,39],21:[2,39]},{18:84,38:[1,27]},{19:[1,85]},{18:86,38:[1,27]},{18:87,38:[1,27]},{18:88,38:[1,27]},{4:30,5:3,6:4,7:[1,5],8:[1,6],13:36,15:89,17:34,18:25,19:[1,26],20:29,22:31,23:32,24:33,29:[1,35],30:[1,7],31:[1,8],32:[1,10],33:[1,11],34:[1,12],35:[1,9],38:[1,27]},{14:[2,40],16:[2,40],21:[2,40],29:[2,40]},{14:[2,32],16:[2,32],21:[2,32]},{14:[2,33],16:[2,33],21:[2,33]},{14:[2,34],16:[2,34],21:[2,34]},{14:[2,35],16:[2,35],21:[2,35]},{16:[1,90],21:[1,45]},{14:[2,43],16:[2,43],21:[2,43],29:[2,43]}],
+table: [{1:[2,1],3:1,4:2,5:9,6:12,7:[1,13],8:[1,14],9:4,14:11,17:8,18:15,19:[1,16],20:3,22:5,23:6,24:7,29:[1,10],30:[1,17],31:[1,18],32:[1,20],33:[1,21],34:[1,22],35:[1,19],38:[1,23]},{1:[3]},{1:[2,2],21:[1,24]},{1:[2,17],16:[2,17],21:[2,17]},{1:[2,19],10:[1,25],13:[1,26],15:[1,27],16:[2,19],21:[2,19]},{1:[2,20],15:[1,28],16:[2,20],21:[2,20],29:[1,30],36:29},{1:[2,21],15:[1,31],16:[2,21],21:[2,21]},{1:[2,22],13:[1,32],15:[1,33],16:[2,22],21:[2,22]},{1:[2,23],13:[1,34],16:[2,23],21:[2,23]},{1:[2,8],8:[1,35],10:[2,8],13:[2,8],15:[2,8],16:[2,8],21:[2,8]},{13:[1,36]},{1:[2,13],13:[2,13],16:[2,13],21:[2,13]},{1:[2,3],7:[1,37],8:[2,3],10:[2,3],13:[2,3],15:[2,3],16:[2,3],21:[2,3]},{6:38,30:[1,17],31:[1,18],32:[1,20],33:[1,21],34:[1,22],35:[1,19]},{6:39,30:[1,17],31:[1,18],32:[1,20],33:[1,21],34:[1,22],35:[1,19]},{1:[2,15],10:[2,15],13:[2,15],15:[2,15],16:[2,15],21:[2,15]},{1:[2,16],10:[2,16],13:[2,16],15:[2,16],16:[2,16],21:[2,16]},{1:[2,44],7:[2,44],8:[2,44],10:[2,44],11:[2,44],13:[2,44],15:[2,44],16:[2,44],21:[2,44],26:[2,44],27:[2,44],28:[2,44],29:[2,44]},{1:[2,45],7:[2,45],8:[2,45],10:[2,45],11:[2,45],13:[2,45],15:[2,45],16:[2,45],21:[2,45],26:[2,45],27:[2,45],28:[2,45],29:[2,45]},{1:[2,46],7:[2,46],8:[2,46],10:[2,46],11:[2,46],13:[2,46],15:[2,46],16:[2,46],21:[2,46],26:[2,46],27:[2,46],28:[2,46],29:[2,46]},{1:[2,47],7:[2,47],8:[2,47],10:[2,47],11:[2,47],13:[2,47],15:[2,47],16:[2,47],21:[2,47],26:[2,47],27:[2,47],28:[2,47],29:[2,47]},{1:[2,48],7:[2,48],8:[2,48],10:[2,48],11:[2,48],13:[2,48],15:[2,48],16:[2,48],21:[2,48],26:[2,48],27:[2,48],28:[2,48],29:[2,48]},{1:[2,49],7:[2,49],8:[2,49],10:[2,49],11:[2,49],13:[2,49],15:[2,49],16:[2,49],21:[2,49],26:[2,49],27:[2,49],28:[2,49],29:[2,49]},{1:[2,51],6:40,10:[2,51],11:[2,51],13:[2,51],15:[2,51],16:[2,51],21:[2,51],27:[2,51],29:[2,51],30:[1,17],31:[1,18],32:[1,20],33:[1,21],34:[1,22],35:[1,19]},{5:9,6:12,7:[1,13],8:[1,14],9:4,14:11,17:8,18:15,19:[1,16],20:41,22:5,23:6,24:7,29:[1,10],30:[1,17],31:[1,18],32:[1,20],33:[1,21],34:[1,22],35:[1,19],38:[1,23]},{6:45,11:[1,42],12:43,25:44,30:[1,17],31:[1,18],32:[1,20],33:[1,21],34:[1,22],35:[1,19]},{14:46,18:15,19:[1,16],38:[1,23]},{4:47,5:9,6:12,7:[1,13],8:[1,14],9:4,14:11,17:8,18:15,19:[1,16],20:3,22:5,23:6,24:7,29:[1,10],30:[1,17],31:[1,18],32:[1,20],33:[1,21],34:[1,22],35:[1,19],38:[1,23]},{4:48,5:9,6:12,7:[1,13],8:[1,14],9:4,14:11,17:8,18:15,19:[1,16],20:3,22:5,23:6,24:7,29:[1,10],30:[1,17],31:[1,18],32:[1,20],33:[1,21],34:[1,22],35:[1,19],38:[1,23]},{1:[2,42],15:[2,42],16:[2,42],21:[2,42],29:[2,42]},{13:[1,49]},{4:50,5:9,6:12,7:[1,13],8:[1,14],9:4,14:11,17:8,18:15,19:[1,16],20:3,22:5,23:6,24:7,29:[1,10],30:[1,17],31:[1,18],32:[1,20],33:[1,21],34:[1,22],35:[1,19],38:[1,23]},{14:51,18:15,19:[1,16],38:[1,23]},{4:52,5:9,6:12,7:[1,13],8:[1,14],9:4,14:11,17:8,18:15,19:[1,16],20:3,22:5,23:6,24:7,29:[1,10],30:[1,17],31:[1,18],32:[1,20],33:[1,21],34:[1,22],35:[1,19],38:[1,23]},{14:53,18:15,19:[1,16],38:[1,23]},{6:54,30:[1,17],31:[1,18],32:[1,20],33:[1,21],34:[1,22],35:[1,19]},{30:[1,56],31:[1,57],32:[1,58],33:[1,59],34:[1,60],35:[1,55]},{6:61,30:[1,17],31:[1,18],32:[1,20],33:[1,21],34:[1,22],35:[1,19]},{1:[2,5],8:[2,5],10:[2,5],13:[2,5],15:[2,5],16:[2,5],21:[2,5]},{1:[2,6],8:[2,6],10:[2,6],13:[2,6],15:[2,6],16:[2,6],21:[2,6]},{1:[2,50],10:[2,50],11:[2,50],13:[2,50],15:[2,50],16:[2,50],21:[2,50],27:[2,50],29:[2,50]},{1:[2,18],16:[2,18],21:[2,18]},{1:[2,9],10:[2,9],13:[2,9],15:[2,9],16:[2,9],21:[2,9]},{11:[1,62],13:[1,63]},{11:[2,24],13:[2,24]},{26:[1,64],28:[1,65]},{1:[2,11],10:[2,11],13:[2,11],15:[2,11],16:[2,11],21:[2,11]},{16:[1,66],21:[1,24]},{16:[1,67],21:[1,24]},{37:[1,68]},{16:[1,69],21:[1,24]},{1:[2,38],13:[2,38],15:[2,38],16:[2,38],21:[2,38]},{16:[1,70],21:[1,24]},{1:[2,14],13:[2,14],16:[2,14],21:[2,14]},{1:[2,7],8:[2,7],10:[2,7],13:[2,7],15:[2,7],16:[2,7],21:[2,7]},{13:[1,71]},{13:[1,72]},{13:[1,73]},{13:[1,74]},{13:[1,75]},{1:[2,37],13:[2,37],15:[2,37],16:[2,37],21:[2,37]},{1:[2,4],8:[2,4],10:[2,4],13:[2,4],15:[2,4],16:[2,4],21:[2,4]},{1:[2,10],10:[2,10],13:[2,10],15:[2,10],16:[2,10],21:[2,10]},{6:45,25:76,30:[1,17],31:[1,18],32:[1,20],33:[1,21],34:[1,22],35:[1,19]},{6:77,18:78,19:[1,79],30:[1,17],31:[1,18],32:[1,20],33:[1,21],34:[1,22],35:[1,19],38:[1,23]},{6:45,25:80,30:[1,17],31:[1,18],32:[1,20],33:[1,21],34:[1,22],35:[1,19]},{1:[2,12],10:[2,12],13:[2,12],15:[2,12],16:[2,12],21:[2,12]},{1:[2,41],15:[2,41],16:[2,41],21:[2,41],29:[2,41]},{15:[1,81]},{1:[2,36],15:[2,36],16:[2,36],21:[2,36]},{1:[2,39],13:[2,39],15:[2,39],16:[2,39],21:[2,39]},{18:82,38:[1,23]},{19:[1,83]},{18:84,38:[1,23]},{18:85,38:[1,23]},{18:86,38:[1,23]},{11:[2,25],13:[2,25]},{11:[2,26],13:[2,26],27:[1,87]},{11:[2,27],13:[2,27],27:[1,88]},{11:[2,30],13:[2,30]},{11:[2,31],13:[2,31]},{4:89,5:9,6:12,7:[1,13],8:[1,14],9:4,14:11,17:8,18:15,19:[1,16],20:3,22:5,23:6,24:7,29:[1,10],30:[1,17],31:[1,18],32:[1,20],33:[1,21],34:[1,22],35:[1,19],38:[1,23]},{1:[2,40],15:[2,40],16:[2,40],21:[2,40],29:[2,40]},{1:[2,32],15:[2,32],16:[2,32],21:[2,32]},{1:[2,33],15:[2,33],16:[2,33],21:[2,33]},{1:[2,34],15:[2,34],16:[2,34],21:[2,34]},{1:[2,35],15:[2,35],16:[2,35],21:[2,35]},{11:[2,28],13:[2,28]},{11:[2,29],13:[2,29]},{16:[1,90],21:[1,24]},{1:[2,43],15:[2,43],16:[2,43],21:[2,43],29:[2,43]}],
defaultActions: {},
parseError: function parseError(str, hash) {
throw new Error(str);
@@ -354,7 +354,7 @@ exports.main = function commonjsMain(args) {
if (typeof module !== 'undefined' && require.main === module) {
exports.main(typeof process !== 'undefined' ? process.argv.slice(1) : require("system").args);
}
-}var AssociationCollection, COMMENT, Cache, Collection, Compile, DynamicNode, Event, IDENTIFIER, KEYWORDS, LITERAL, Lexer, MULTI_DENT, Model, Node, Property, PropertyAccessor, PropertyDefinition, STRING, Serenade, View, WHITESPACE, capitalize, compile, compileAll, def, defineEvent, defineProperty, extend, format, getValue, globalDependencies, idCounter, isArray, isArrayIndex, normalize, pairToObject, safeDelete, safePush, serializeObject, settings, triggerGlobal,
+}var AssociationCollection, COMMENT, Cache, Collection, Compile, CompiledView, DynamicNode, Event, IDENTIFIER, KEYWORDS, LITERAL, Lexer, MULTI_DENT, Model, Node, Property, PropertyAccessor, PropertyDefinition, STRING, Serenade, View, WHITESPACE, assignUnlessEqual, capitalize, compile, def, defineEvent, defineOptions, defineProperty, extend, format, getValue, globalDependencies, idCounter, isArray, isArrayIndex, merge, normalize, pairToObject, safeDelete, safePush, serializeObject, settings, triggerGlobal,
__hasProp = {}.hasOwnProperty,
__slice = [].slice,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
@@ -366,25 +366,54 @@ settings = {
def = Object.defineProperty;
+defineOptions = function(object, name) {
+ return def(object, name, {
+ get: function() {
+ var options;
+ if (!this.hasOwnProperty("_" + name)) {
+ options = name in Object.getPrototypeOf(this) ? Object.create(Object.getPrototypeOf(this)[name]) : {};
+ def(this, "_" + name, {
+ configurable: true,
+ writable: true,
+ value: options
+ });
+ }
+ return this["_" + name];
+ }
+ });
+};
+
extend = function(target, source, enumerable) {
- var key, value, _results;
+ var key, value;
if (enumerable == null) {
enumerable = true;
}
- _results = [];
for (key in source) {
if (!__hasProp.call(source, key)) continue;
value = source[key];
if (enumerable) {
- _results.push(target[key] = value);
+ target[key] = value;
} else {
- _results.push(def(target, key, {
+ def(target, key, {
value: value,
configurable: true
- }));
+ });
}
}
- return _results;
+ return target;
+};
+
+assignUnlessEqual = function(object, prop, value) {
+ if (object[prop] !== value) {
+ return object[prop] = value;
+ }
+};
+
+merge = function(target, source, enumerable) {
+ if (enumerable == null) {
+ enumerable = true;
+ }
+ return extend(extend({}, target, enumerable), source, enumerable);
};
format = function(model, key) {
@@ -460,11 +489,18 @@ Event = (function() {
this.object = object;
this.name = name;
this.options = options;
- this.prop = "_s_" + this.name + "_listeners";
- this.queueName = "_s_" + name + "_queue";
- this.async = "async" in this.options ? this.options.async : settings.async;
}
+ def(Event.prototype, "async", {
+ get: function() {
+ if ("async" in this.options) {
+ return this.options.async;
+ } else {
+ return settings.async;
+ }
+ }
+ });
+
Event.prototype.trigger = function() {
var args, _base,
_this = this;
@@ -483,7 +519,7 @@ Event = (function() {
if (this.options.bind) {
this.options.bind.call(this.object, fun);
}
- return safePush(this.object, this.prop, fun);
+ return safePush(this.object._s, "listeners_" + this.name, fun);
};
Event.prototype.one = function(fun) {
@@ -499,7 +535,7 @@ Event = (function() {
};
Event.prototype.unbind = function(fun) {
- safeDelete(this.object, this.prop, fun);
+ safeDelete(this.object._s, "listeners_" + this.name, fun);
if (this.options.unbind) {
return this.options.unbind.call(this.object, fun);
}
@@ -509,9 +545,9 @@ Event = (function() {
var args, perform, _i, _len, _ref,
_this = this;
perform = function(args) {
- if (_this.object[_this.prop]) {
- return _this.object[_this.prop].forEach(function(fun) {
- return fun.apply(_this.object, args);
+ if (_this.listeners) {
+ return _this.listeners.forEach(function(listener) {
+ return listener.apply(_this.object, args);
});
}
};
@@ -529,22 +565,19 @@ Event = (function() {
def(Event.prototype, "listeners", {
get: function() {
- return this.object[this.prop];
+ return this.object._s["listeners_" + this.name];
}
});
def(Event.prototype, "queue", {
get: function() {
- if (!this.object.hasOwnProperty(this.queueName)) {
+ if (!this.object._s.hasOwnProperty("queue_" + this.name)) {
this.queue = [];
}
- return this.object[this.queueName];
+ return this.object._s["queue_" + this.name];
},
set: function(val) {
- return def(this.object, this.queueName, {
- value: val,
- configurable: true
- });
+ return this.object._s["queue_" + this.name] = val;
}
});
@@ -556,6 +589,9 @@ defineEvent = function(object, name, options) {
if (options == null) {
options = {};
}
+ if (!("_s" in object)) {
+ defineOptions(object, "_s");
+ }
return def(object, name, {
configurable: true,
get: function() {
@@ -703,13 +739,17 @@ Collection = (function() {
}
};
- Collection.prototype.first = function() {
- return this[0];
- };
+ def(Collection.prototype, "first", {
+ get: function() {
+ return this[0];
+ }
+ });
- Collection.prototype.last = function() {
- return this[this.length - 1];
- };
+ def(Collection.prototype, "last", {
+ get: function() {
+ return this[this.length - 1];
+ }
+ });
Collection.prototype.toArray = function() {
var array, index, val;
@@ -974,18 +1014,24 @@ PropertyDefinition = (function() {
this.addDependency(name);
}
}
- this.async = "async" in options ? options.async : settings.async;
- this.eventOptions = {
- async: this.async,
- bind: function() {
- return this[name];
- },
- optimize: function(queue) {
- return queue[queue.length - 1];
- }
- };
}
+ def(PropertyDefinition.prototype, "eventOptions", {
+ get: function() {
+ var name;
+ name = this.name;
+ return {
+ async: this.async != null ? this.async : settings.async,
+ bind: function() {
+ return this[name];
+ },
+ optimize: function(queue) {
+ return queue[queue.length - 1];
+ }
+ };
+ }
+ });
+
PropertyDefinition.prototype.addDependency = function(name) {
var subname, type, _ref, _ref1;
if (this.dependencies.indexOf(name) === -1) {
@@ -1021,18 +1067,22 @@ PropertyAccessor = (function() {
this.definition = definition;
this.object = object;
this.name = this.definition.name;
- this.valueName = "_s_" + this.name + "_val";
+ this.valueName = "val_" + this.name;
this.event = new Event(this.object, this.name + "_change", this.definition.eventOptions);
}
PropertyAccessor.prototype.set = function(value) {
+ var val;
if (typeof value === "function") {
return this.definition.get = value;
} else {
+ if (this.definition.changed) {
+ val = this.get();
+ }
if (this.definition.set) {
this.definition.set.call(this.object, value);
} else {
- def(this.object, this.valueName, {
+ def(this.object._s, this.valueName, {
value: value,
configurable: true
});
@@ -1045,21 +1095,24 @@ PropertyAccessor = (function() {
var listener, value,
_this = this;
this.registerGlobal();
- if (this.definition.get) {
+ if (this.definition.get && !(this.definition.cache && this.valueName in this.object._s)) {
listener = function(name) {
return _this.definition.addDependency(name);
};
if (!("dependsOn" in this.definition)) {
- this.object._s_property_access.bind(listener);
+ this.object._s.property_access.bind(listener);
}
value = this.definition.get.call(this.object);
+ if (this.definition.cache) {
+ this.object._s[this.valueName] = value;
+ }
if (!("dependsOn" in this.definition)) {
- this.object._s_property_access.unbind(listener);
+ this.object._s.property_access.unbind(listener);
}
} else {
- value = this.object[this.valueName];
+ value = this.object._s[this.valueName];
}
- this.object._s_property_access.trigger(this.name);
+ this.object._s.property_access.trigger(this.name);
return value;
};
@@ -1073,11 +1126,8 @@ PropertyAccessor = (function() {
PropertyAccessor.prototype.registerGlobal = function() {
var name, subname, type, _i, _len, _ref, _ref1, _results;
- if (!this.object["_s_glb_" + this.name]) {
- def(this.object, "_s_glb_" + this.name, {
- value: true,
- configurable: true
- });
+ if (!this.object._s["glb_" + this.name]) {
+ this.object._s["glb_" + this.name] = true;
_ref = this.definition.globalDependencies;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -1096,26 +1146,36 @@ PropertyAccessor = (function() {
};
PropertyAccessor.prototype.trigger = function() {
- var changes, name, names, value, _i, _len, _ref, _results;
- names = [this.name].concat(this.dependents);
- changes = {};
- for (_i = 0, _len = names.length; _i < _len; _i++) {
- name = names[_i];
- changes[name] = this.object[name];
- }
- if ((_ref = this.object.changed) != null) {
- if (typeof _ref.trigger === "function") {
- _ref.trigger(changes);
+ var changes, name, prop, value, _i, _len, _ref, _ref1;
+ this.clearCache();
+ if (this.hasChanged()) {
+ value = this.get();
+ changes = {};
+ _ref = this.dependents;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ name = _ref[_i];
+ if (name !== this.name) {
+ changes[name] = this.object[name];
+ }
}
+ this.event.trigger(value);
+ for (name in changes) {
+ if (!__hasProp.call(changes, name)) continue;
+ value = changes[name];
+ prop = this.object[name + "_property"];
+ prop.clearCache();
+ if (prop.hasChanged()) {
+ prop.event.trigger(value);
+ }
+ }
+ changes[this.name] = value;
+ if ((_ref1 = this.object.changed) != null) {
+ if (typeof _ref1.trigger === "function") {
+ _ref1.trigger(changes);
+ }
+ }
+ return triggerGlobal(this.object, Object.keys(changes));
}
- triggerGlobal(this.object, names);
- _results = [];
- for (name in changes) {
- if (!__hasProp.call(changes, name)) continue;
- value = changes[name];
- _results.push(this.object[name + "_property"].event.trigger(value));
- }
- return _results;
};
PropertyAccessor.prototype.bind = function(fun) {
@@ -1137,7 +1197,7 @@ PropertyAccessor = (function() {
deps = [];
findDependencies = function(name) {
var property, _i, _len, _ref, _ref1, _results;
- _ref = _this.object._s_properties;
+ _ref = _this.object._s.properties;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
property = _ref[_i];
@@ -1161,6 +1221,27 @@ PropertyAccessor = (function() {
}
});
+ PropertyAccessor.prototype.clearCache = function() {
+ if (this.definition.cache && this.definition.get) {
+ return delete this.object._s[this.valueName];
+ }
+ };
+
+ PropertyAccessor.prototype.hasChanged = function() {
+ var changed, oldValueName, value;
+ if (this.definition.changed === false) {
+ return false;
+ } else if (this.definition.changed) {
+ value = this.get();
+ oldValueName = "old_val_" + this.name;
+ changed = this.object._s.hasOwnProperty(oldValueName) ? this.definition.changed.call(this.object, this.object._s[oldValueName], value) : true;
+ this.object._s[oldValueName] = value;
+ return changed;
+ } else {
+ return true;
+ }
+ };
+
return PropertyAccessor;
})();
@@ -1171,8 +1252,11 @@ defineProperty = function(object, name, options) {
options = {};
}
definition = new PropertyDefinition(name, options);
- safePush(object, "_s_properties", definition);
- defineEvent(object, "_s_property_access");
+ if (!("_s" in object)) {
+ defineOptions(object, "_s");
+ }
+ safePush(object._s, "properties", definition);
+ defineEvent(object._s, "property_access");
def(object, name, {
get: function() {
return this[name + "_property"].get();
@@ -1209,30 +1293,6 @@ idCounter = 1;
Model = (function() {
- defineEvent(Model.prototype, "saved");
-
- defineEvent(Model.prototype, "changed", {
- optimize: function(queue) {
- var item, result, _i, _len;
- result = {};
- for (_i = 0, _len = queue.length; _i < _len; _i++) {
- item = queue[_i];
- extend(result, item[0]);
- }
- return [result];
- }
- });
-
- Model.belongsTo = function() {
- var _ref;
- return (_ref = this.prototype).belongsTo.apply(_ref, arguments);
- };
-
- Model.hasMany = function() {
- var _ref;
- return (_ref = this.prototype).hasMany.apply(_ref, arguments);
- };
-
Model.identityMap = true;
Model.find = function(id) {
@@ -1278,15 +1338,8 @@ Model = (function() {
return _results;
};
- Model.properties = function() {
- var name, names, _i, _len, _results;
- names = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
- _results = [];
- for (_i = 0, _len = names.length; _i < _len; _i++) {
- name = names[_i];
- _results.push(this.property(name));
- }
- return _results;
+ Model.event = function(name, options) {
+ return defineEvent(this.prototype, name, options);
};
Model.delegate = function() {
@@ -1295,7 +1348,7 @@ Model = (function() {
names = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), options = arguments[_i++];
to = options.to;
return names.forEach(function(name) {
- var propName;
+ var propName, propOptions;
propName = name;
if (options.prefix === true) {
propName = to + capitalize(name);
@@ -1307,8 +1360,8 @@ Model = (function() {
} else if (options.suffix) {
propName = propName + options.suffix;
}
- return _this.property(propName, {
- dependsOn: "" + to + "." + name,
+ propOptions = merge(options, {
+ dependsOn: options.dependsOn || ("" + to + "." + name),
get: function() {
var _ref;
return (_ref = this[to]) != null ? _ref[name] : void 0;
@@ -1318,31 +1371,33 @@ Model = (function() {
return (_ref = this[to]) != null ? _ref[name] = value : void 0;
}
});
+ return _this.property(propName, propOptions);
});
};
Model.collection = function(name, options) {
+ var propOptions;
if (options == null) {
options = {};
}
- extend(options, {
+ propOptions = merge(options, {
get: function() {
var valueName,
_this = this;
- valueName = "_s_" + name + "_val";
- if (!this[valueName]) {
- this[valueName] = new Collection([]);
- this[valueName].change.bind(function() {
+ valueName = "val_" + name;
+ if (!this._s[valueName]) {
+ this._s[valueName] = new Collection([]);
+ this._s[valueName].change.bind(function() {
return _this[name + "_property"].trigger();
});
}
- return this[valueName];
+ return this._s[valueName];
},
set: function(value) {
return this[name].update(value);
}
});
- this.property(name, options);
+ this.property(name, propOptions);
return this.property(name + 'Count', {
get: function() {
return this[name].length;
@@ -1351,28 +1406,29 @@ Model = (function() {
});
};
- Model.belongsTo = function(name, attributes) {
- if (attributes == null) {
- attributes = {};
+ Model.belongsTo = function(name, options) {
+ var propOptions;
+ if (options == null) {
+ options = {};
}
- extend(attributes, {
+ propOptions = merge(options, {
set: function(model) {
var previous, valueName;
- valueName = "_s_" + name + "_val";
- if (model && model.constructor === Object && attributes.as) {
- model = new (attributes.as())(model);
+ valueName = "val_" + name;
+ if (model && model.constructor === Object && options.as) {
+ model = new (options.as())(model);
}
- previous = this[valueName];
- this[valueName] = model;
- if (attributes.inverseOf && !model[attributes.inverseOf].includes(this)) {
+ previous = this._s[valueName];
+ this._s[valueName] = model;
+ if (options.inverseOf && !model[options.inverseOf].includes(this)) {
if (previous) {
- previous[attributes.inverseOf]["delete"](this);
+ previous[options.inverseOf]["delete"](this);
}
- return model[attributes.inverseOf].push(this);
+ return model[options.inverseOf].push(this);
}
}
});
- this.property(name, attributes);
+ this.property(name, propOptions);
return this.property(name + 'Id', {
get: function() {
var _ref;
@@ -1380,36 +1436,37 @@ Model = (function() {
},
set: function(id) {
if (id != null) {
- return this[name] = attributes.as().find(id);
+ return this[name] = options.as().find(id);
}
},
dependsOn: name,
- serialize: attributes.serializeId
+ serialize: options.serializeId
});
};
- Model.hasMany = function(name, attributes) {
- if (attributes == null) {
- attributes = {};
+ Model.hasMany = function(name, options) {
+ var propOptions;
+ if (options == null) {
+ options = {};
}
- extend(attributes, {
+ propOptions = merge(options, {
get: function() {
var valueName,
_this = this;
- valueName = "_s_" + name + "_val";
- if (!this[valueName]) {
- this[valueName] = new AssociationCollection(this, attributes, []);
- this[valueName].change.bind(function() {
+ valueName = "val_" + name;
+ if (!this._s[valueName]) {
+ this._s[valueName] = new AssociationCollection(this, options, []);
+ this._s[valueName].change.bind(function() {
return _this[name + "_property"].trigger();
});
}
- return this[valueName];
+ return this._s[valueName];
},
set: function(value) {
return this[name].update(value);
}
});
- this.property(name, attributes);
+ this.property(name, propOptions);
this.property(name + 'Ids', {
get: function() {
return new Collection(this[name]).map(function(item) {
@@ -1423,14 +1480,14 @@ Model = (function() {
_results = [];
for (_i = 0, _len = ids.length; _i < _len; _i++) {
id = ids[_i];
- _results.push(attributes.as().find(id));
+ _results.push(options.as().find(id));
}
return _results;
})();
return this[name].update(objects);
},
dependsOn: name,
- serialize: attributes.serializeIds
+ serialize: options.serializeIds
});
return this.property(name + 'Count', {
get: function() {
@@ -1441,10 +1498,11 @@ Model = (function() {
};
Model.selection = function(name, options) {
+ var propOptions;
if (options == null) {
options = {};
}
- this.property(name, {
+ propOptions = merge(options, {
get: function() {
return this[options.from].filter(function(item) {
return item[options.filter];
@@ -1452,6 +1510,7 @@ Model = (function() {
},
dependsOn: "" + options.from + ":" + options.filter
});
+ this.property(name, propOptions);
return this.property(name + 'Count', {
get: function() {
return this[name].length;
@@ -1473,13 +1532,24 @@ Model = (function() {
set: function(val) {
Cache.unset(this.constructor, this.id);
Cache.set(this.constructor, val, this);
- return def(this, "_s_id_val", {
- value: val,
- configurable: true
- });
+ return this._s.val_id = val;
},
get: function() {
- return this._s_id_val;
+ return this._s.val_id;
+ }
+ });
+
+ Model.event("saved");
+
+ Model.event("changed", {
+ optimize: function(queue) {
+ var item, result, _i, _len;
+ result = {};
+ for (_i = 0, _len = queue.length; _i < _len; _i++) {
+ item = queue[_i];
+ extend(result, item[0]);
+ }
+ return [result];
}
});
@@ -1518,7 +1588,7 @@ Model = (function() {
Model.prototype.toJSON = function() {
var key, property, serialized, value, _i, _len, _ref, _ref1;
serialized = {};
- _ref = this._s_properties;
+ _ref = this._s.properties;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
property = _ref[_i];
if (typeof property.serialize === 'string') {
@@ -1748,9 +1818,12 @@ Node = (function() {
return (_ref = this.element.parentNode) != null ? _ref.removeChild(this.element) : void 0;
};
- Node.prototype.lastElement = function() {
- return this.element;
- };
+ def(Node.prototype, "lastElement", {
+ configurable: true,
+ get: function() {
+ return this.element;
+ }
+ });
Node.prototype.nodes = function() {
return this.children;
@@ -1795,8 +1868,9 @@ Node = (function() {
if (this.boundClasses.length) {
classes = classes.concat(this.boundClasses.toArray());
}
+ classes.sort();
if (classes.length) {
- return this.element.className = classes.join(' ');
+ return assignUnlessEqual(this.element, "className", classes.join(' '));
} else {
return this.element.removeAttribute("class");
}
@@ -1839,7 +1913,7 @@ DynamicNode = (function(_super) {
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
node = _ref[_i];
node.insertAfter(last);
- _results.push(last = node.lastElement());
+ _results.push(last = node.lastElement);
}
return _results;
}
@@ -1876,11 +1950,11 @@ DynamicNode = (function(_super) {
DynamicNode.prototype.insertNodeSet = function(index, nodes) {
var last, node, _i, _len, _ref, _ref1;
- last = ((_ref = this.nodeSets[index - 1]) != null ? (_ref1 = _ref.last()) != null ? _ref1.lastElement() : void 0 : void 0) || this.anchor;
+ last = ((_ref = this.nodeSets[index - 1]) != null ? (_ref1 = _ref.last) != null ? _ref1.lastElement : void 0 : void 0) || this.anchor;
for (_i = 0, _len = nodes.length; _i < _len; _i++) {
node = nodes[_i];
node.insertAfter(last);
- last = node.lastElement();
+ last = node.lastElement;
}
return this.nodeSets.insertAt(index, new Collection(nodes));
};
@@ -1911,10 +1985,13 @@ DynamicNode = (function(_super) {
return this.rebuild();
};
- DynamicNode.prototype.lastElement = function() {
- var _ref, _ref1;
- return ((_ref = this.nodeSets.last()) != null ? (_ref1 = _ref.last()) != null ? _ref1.lastElement() : void 0 : void 0) || this.anchor;
- };
+ def(DynamicNode.prototype, "lastElement", {
+ configurable: true,
+ get: function() {
+ var _ref, _ref1;
+ return ((_ref = this.nodeSets.last) != null ? (_ref1 = _ref.last) != null ? _ref1.lastElement : void 0 : void 0) || this.anchor;
+ }
+ });
return DynamicNode;
@@ -1934,7 +2011,7 @@ Property = {
style: function(ast, node, model, controller) {
var update;
update = function() {
- return node.element.style[ast.name] = getValue(ast, model);
+ return assignUnlessEqual(node.element.style, ast.name, getValue(ast, model));
};
update();
if (ast.bound) {
@@ -1953,7 +2030,9 @@ Property = {
var update;
update = function() {
if (model[ast.value]) {
- node.boundClasses.push(ast.name);
+ if (!node.boundClasses.includes(ast.name)) {
+ node.boundClasses.push(ast.name);
+ }
} else {
node.boundClasses["delete"](ast.name);
}
@@ -1987,9 +2066,7 @@ Property = {
if (val === void 0) {
val = "";
}
- if (element.value !== val) {
- return element.value = val;
- }
+ return assignUnlessEqual(element, "value", val);
}
};
modelUpdated();
@@ -2018,19 +2095,23 @@ Property = {
var value;
value = getValue(ast, model);
if (ast.name === 'value') {
- return element.value = value || '';
+ return assignUnlessEqual(element, "value", value || '');
} else if (node.ast.name === 'input' && ast.name === 'checked') {
- return element.checked = !!value;
+ return assignUnlessEqual(element, "checked", !!value);
} else if (ast.name === 'class') {
node.attributeClasses = value;
return node.updateClass();
} else if (value === void 0) {
- return element.removeAttribute(ast.name);
+ if (element.hasAttribute(ast.name)) {
+ return element.removeAttribute(ast.name);
+ }
} else {
if (value === 0) {
value = "0";
}
- return element.setAttribute(ast.name, value);
+ if (element.getAttribute(ast.name) !== value) {
+ return element.setAttribute(ast.name, value);
+ }
}
};
if (ast.bound) {
@@ -2052,7 +2133,7 @@ Property = {
Compile = {
element: function(ast, model, controller) {
- var action, child, childNode, element, node, property, _i, _j, _len, _len1, _ref, _ref1, _ref2;
+ var action, child, element, node, property, _i, _j, _len, _len1, _ref, _ref1, _ref2;
element = Serenade.document.createElement(ast.name);
node = new Node(ast, element);
if (ast.id) {
@@ -2061,12 +2142,11 @@ Compile = {
if ((_ref = ast.classes) != null ? _ref.length : void 0) {
element.setAttribute('class', ast.classes.join(' '));
}
- _ref1 = ast.children;
+ node.children = compile(ast.children, model, controller);
+ _ref1 = node.children;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
child = _ref1[_i];
- childNode = compile(child, model, controller);
- childNode.append(element);
- node.children.push(childNode);
+ child.append(element);
}
_ref2 = ast.properties;
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
@@ -2082,19 +2162,21 @@ Compile = {
return node;
},
view: function(ast, model, parent) {
- var controller, skipCallback;
+ var controller, dynamic, skipCallback;
controller = Serenade.controllerFor(ast.argument);
if (!controller) {
skipCallback = true;
controller = parent;
}
- return Serenade._views[ast.argument].node(model, controller, parent, skipCallback);
+ dynamic = new DynamicNode(ast);
+ dynamic.replace([Serenade._views[ast.argument].nodes(model, controller, parent, skipCallback)]);
+ return dynamic;
},
helper: function(ast, model, controller) {
var argument, context, dynamic, helperFunction, render, update, _i, _len, _ref;
dynamic = new DynamicNode(ast);
render = function(model, controller) {
- var child, fragment, node, _i, _len, _ref;
+ var child, children, fragment, _i, _len;
if (model == null) {
model = model;
}
@@ -2102,11 +2184,10 @@ Compile = {
controller = controller;
}
fragment = Serenade.document.createDocumentFragment();
- _ref = ast.children;
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- child = _ref[_i];
- node = compile(child, model, controller);
- node.append(fragment);
+ children = compile(ast.children, model, controller);
+ for (_i = 0, _len = children.length; _i < _len; _i++) {
+ child = children[_i];
+ child.append(fragment);
}
return fragment;
};
@@ -2163,7 +2244,7 @@ Compile = {
node = new Node(ast, textNode);
if (ast.bound) {
node.bindEvent(model["" + ast.value + "_property"], function() {
- return textNode.nodeValue = getText();
+ return assignUnlessEqual(textNode, "nodeValue", getText());
});
}
return node;
@@ -2172,7 +2253,7 @@ Compile = {
var collection, compileItem, dynamic, update,
_this = this;
compileItem = function(item) {
- return compileAll(ast.children, item, controller);
+ return compile(ast.children, item, controller);
};
update = function(dynamic, collection) {
var item;
@@ -2226,7 +2307,7 @@ Compile = {
"in": function(ast, model, controller) {
return this.bound(ast, model, controller, function(dynamic, value) {
if (value) {
- return dynamic.replace([compileAll(ast.children, value, controller)]);
+ return dynamic.replace([compile(ast.children, value, controller)]);
} else {
return dynamic.clear();
}
@@ -2235,9 +2316,9 @@ Compile = {
"if": function(ast, model, controller) {
return this.bound(ast, model, controller, function(dynamic, value) {
if (value) {
- return dynamic.replace([compileAll(ast.children, model, controller)]);
+ return dynamic.replace([compile(ast.children, model, controller)]);
} else if (ast["else"]) {
- return dynamic.replace([compileAll(ast["else"].children, model, controller)]);
+ return dynamic.replace([compile(ast["else"].children, model, controller)]);
} else {
return dynamic.clear();
}
@@ -2245,31 +2326,26 @@ Compile = {
},
unless: function(ast, model, controller) {
return this.bound(ast, model, controller, function(dynamic, value) {
- var child, nodes;
+ var nodes;
if (value) {
return dynamic.clear();
} else {
- nodes = (function() {
- var _i, _len, _ref, _results;
- _ref = ast.children;
- _results = [];
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- child = _ref[_i];
- _results.push(compile(child, model, controller));
- }
- return _results;
- })();
+ nodes = compile(ast.children, model, controller);
return dynamic.replace([nodes]);
}
});
},
bound: function(ast, model, controller, callback) {
- var dynamic, update;
+ var dynamic, lastValue, update;
dynamic = new DynamicNode(ast);
+ lastValue = {};
update = function() {
var value;
value = model[ast.argument];
- return callback(dynamic, value);
+ if (value !== lastValue) {
+ callback(dynamic, value);
+ }
+ return lastValue = value;
};
update();
dynamic.bindEvent(model["" + ast.argument + "_property"], update);
@@ -2283,7 +2359,7 @@ normalize = function(val) {
return [];
}
reduction = function(aggregate, element) {
- var child, div, _i, _len, _ref;
+ var child, div, _i, _j, _len, _len1, _ref, _ref1;
if (typeof element === "string") {
div = Serenade.document.createElement("div");
div.innerHTML = element;
@@ -2292,6 +2368,12 @@ normalize = function(val) {
child = _ref[_i];
aggregate.push(child);
}
+ } else if (element.nodeName === "#document-fragment") {
+ _ref1 = element.childNodes;
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
+ child = _ref1[_j];
+ aggregate.push(child);
+ }
} else {
aggregate.push(element);
}
@@ -2300,16 +2382,12 @@ normalize = function(val) {
return [].concat(val).reduce(reduction, []);
};
-compile = function(ast, model, controller) {
- return Compile[ast.type](ast, model, controller);
-};
-
-compileAll = function(asts, model, controller) {
+compile = function(asts, model, controller) {
var ast, _i, _len, _results;
_results = [];
for (_i = 0, _len = asts.length; _i < _len; _i++) {
ast = asts[_i];
- _results.push(compile(ast, model, controller));
+ _results.push(Compile[ast.type](ast, model, controller));
}
return _results;
};
@@ -2329,6 +2407,41 @@ parser.lexer = {
}
};
+CompiledView = (function() {
+
+ function CompiledView(nodes) {
+ this.nodes = nodes;
+ }
+
+ CompiledView.prototype.remove = function() {
+ var node, _i, _len, _ref, _results;
+ _ref = this.nodes;
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ node = _ref[_i];
+ _results.push(node.remove());
+ }
+ return _results;
+ };
+
+ def(CompiledView.prototype, "fragment", {
+ enumerable: true,
+ get: function() {
+ var fragment, node, _i, _len, _ref;
+ fragment = Serenade.document.createDocumentFragment();
+ _ref = this.nodes;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ node = _ref[_i];
+ node.append(fragment);
+ }
+ return fragment;
+ }
+ });
+
+ return CompiledView;
+
+})();
+
View = (function() {
function View(name, view) {
@@ -2354,11 +2467,11 @@ View = (function() {
View.prototype.render = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
- return this.node.apply(this, args).element;
+ return this.compile.apply(this, args).fragment;
};
- View.prototype.node = function(model, controller, parent, skipCallback) {
- var node;
+ View.prototype.nodes = function(model, controller, parent, skipCallback) {
+ var nodes;
if (this.name) {
controller || (controller = Serenade.controllerFor(this.name, model));
}
@@ -2366,13 +2479,21 @@ View = (function() {
if (typeof controller === "function") {
controller = new controller(model, parent);
}
- node = compile(this.parse(), model, controller);
+ nodes = compile(this.parse(), model, controller);
if (!skipCallback) {
if (typeof controller.loaded === "function") {
- controller.loaded(node.element, model);
+ controller.loaded.apply(controller, __slice.call(nodes.map(function(node) {
+ return node.element;
+ })).concat([model]));
}
}
- return node;
+ return nodes;
+ };
+
+ View.prototype.compile = function() {
+ var args;
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ return new CompiledView(this.nodes.apply(this, args));
};
return View;
@@ -2392,7 +2513,7 @@ Serenade = function(wrapped) {
};
extend(Serenade, {
- VERSION: '0.4.0',
+ VERSION: '0.4.1',
_views: {},
_controllers: {},
document: typeof window !== "undefined" && window !== null ? window.document : void 0,
@@ -2419,13 +2540,9 @@ extend(Serenade, {
clearIdentityMap: function() {
return Cache._identityMap = {};
},
- clearLocalStorage: function() {
- return Cache._storage.clear();
- },
clearCache: function() {
var key, value, _i, _len, _results;
Serenade.clearIdentityMap();
- Serenade.clearLocalStorage();
_results = [];
for (key = _i = 0, _len = globalDependencies.length; _i < _len; key = ++_i) {
value = globalDependencies[key];
View
2  lib/serenade/version.rb
@@ -1,4 +1,4 @@
module Serenade
# Serenade.js version this gem is bundled with.
- VERSION = "0.4.0"
+ VERSION = "0.4.1"
end
View
2  spec/serenade_spec.rb
@@ -6,7 +6,7 @@
describe Serenade::Renderer do
describe "#parse" do
it "returns a parsed Sereande template" do
- result = Serenade::Renderer.new("foo", 'h1 "Hello world"').parse
+ result = Serenade::Renderer.new("foo", 'h1 "Hello world"').parse[0]
result["name"].should eq "h1"
result["children"][0]["type"].should eq "text"
result["children"][0]["value"].should eq "Hello world"
Please sign in to comment.
Something went wrong with that request. Please try again.