Skip to content

Commit

Permalink
support OTF data bindings in blockfile
Browse files Browse the repository at this point in the history
  • Loading branch information
anuvgupta committed Nov 26, 2016
1 parent 4513d67 commit b40d7f4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion block.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,22 @@ Block = function () {
'var $dataCallback = function (block, data, style) {\n\n' + $dataJS + '\n\n};'
);
Block($type, $initCallback, $dataCallback);
} else if ($key.substring(0, 1) == '#') {
$reservedAttributes.push($key);
var $name = $key.substring(1);
var callbackJS = ''
if (Is.obj($blockdata[$key]) && Is.str($blockdata[$key]['__js']))
$callbackJS = $blockdata[$key]['__js'];
eval(
'/* block.js auto-generated data binding\n' +
' ("on-the-fly" data binding callback)\n' +
' block type = ' + type + '\n' +
' block marking = ' + marking + '\n' +
' data name = ' + $name + '\n' +
'*/\n' +
'var $callback = function (' + $name + ') {\n' + $callbackJS + '\n};'
);
this.bind($name, $callback);
} else if ($key.substring(0, 1) == '$') {
$reservedAttributes.push($key);
this.key($key.substring(1), $blockdata[$key]);
Expand Down Expand Up @@ -630,8 +646,10 @@ Block = function () {
element.style[$property] = $style[$property];
}
for (var $key in dataBindings) {
if (dataBindings.hasOwnProperty($key) && $data.hasOwnProperty($key))
if (dataBindings.hasOwnProperty($key) && $data.hasOwnProperty($key)) {
$reservedAttributes.push($key);
dataBindings[$key]($data[$key], this);
}
}
for (var $key in $data) {
if ($data.hasOwnProperty($key) && !Block.inArr($key, $reservedAttributes))
Expand Down
Loading

0 comments on commit b40d7f4

Please sign in to comment.