|
289 | 289 | };
|
290 | 290 | var uiEvents = bindObj.uiEvents || {};
|
291 | 291 | uiEvents.change = uiEvents.change || function (model, element, ui, pointerPath) {
|
292 |
| - return pointerPath.split('/').length <= 2; |
| 292 | + return pointerPath.split('/').length <= 2 && ui.jsonType(pointerPath) !== 'object'; |
293 | 293 | };
|
294 | 294 |
|
295 | 295 | this.bindDom = function (context, model, element) {
|
|
519 | 519 | if (this._model === model) {
|
520 | 520 | result._usedBindings = this._usedBindings.concat(result._usedBindings);
|
521 | 521 | }
|
522 |
| - result.ui = (typeof uiPath === 'string') ? this.ui.path(uiPath) : this.ui; |
| 522 | + if (typeof uiPath !== 'string') { |
| 523 | + uiPath = ''; |
| 524 | + if (!this._model || (model !== this._model) && model._root === this._model._root) { |
| 525 | + uiPath = model._path.replace(/.*\//, ''); |
| 526 | + } |
| 527 | + } |
| 528 | + result.ui = this.ui.path(uiPath); |
| 529 | + if (result.ui.jsonType() !== 'object') { |
| 530 | + result.ui.set({}); |
| 531 | + } |
523 | 532 | return result;
|
524 | 533 | },
|
525 | 534 | selectBinding: function (model, tag, attrs) {
|
|
582 | 591 | }, callback);
|
583 | 592 | },
|
584 | 593 | _updateDom: function (element, tag, attrs, callback) {
|
| 594 | + var thisContext = this; |
585 | 595 | var model = element.boundJsonModel;
|
586 | 596 | var binding = element.boundBinding;
|
587 | 597 | var context = element.boundContext;
|
588 | 598 |
|
| 599 | + var oldRootState = model._root.state; |
589 | 600 | var innerHtml = binding.html(model, tag, attrs, this.ui, processHtml);
|
590 | 601 | if (typeof innerHtml === 'string') {
|
591 | 602 | processHtml(null, innerHtml);
|
592 | 603 | }
|
593 | 604 |
|
594 | 605 | function processHtml(error, innerHtml) {
|
595 |
| - innerHtml = innerHtml.replace(magicRegex, function (match, data) { |
| 606 | + var replacedHtml = innerHtml.replace(magicRegex, function (match, data) { |
596 | 607 | try {
|
597 | 608 | data = JSON.parse(data);
|
598 | 609 | } catch (e) {
|
|
608 | 619 | });
|
609 | 620 | // DEBUG
|
610 | 621 | if (tag !== 'html' && tag !== 'body') {
|
611 |
| - innerHtml = '<span class="debug">' + context._usedBindings.length + ' bindings used</span>' + innerHtml; |
| 622 | + replacedHtml = '<span class="debug">' + context._usedBindings.length + ' bindings used ' + context.ui._path + '</span>' + replacedHtml; |
612 | 623 | }
|
613 | 624 |
|
614 | 625 | var hostElement = element.cloneNode(false);
|
615 |
| - hostElement.innerHTML = innerHtml; |
| 626 | + hostElement.innerHTML = replacedHtml; |
616 | 627 | context._coerceDom(element, hostElement, null, function (err) {
|
| 628 | + if (oldRootState !== model._root.state) { |
| 629 | + console.log('Model changed during rendering: ' + model.url()); |
| 630 | + var newHtml = binding.html(model, tag, attrs, thisContext.ui, function (err2, newHtml) { |
| 631 | + if (newHtml === innerHtml) { |
| 632 | + return callback(error || err); |
| 633 | + } |
| 634 | + console.log('Re-rendering'); |
| 635 | + return thisContext._updateDom(element, tag, attrs, callback); |
| 636 | + }); |
| 637 | + if (typeof newHtml === 'string') { |
| 638 | + if (newHtml === innerHtml) { |
| 639 | + return callback(error || err); |
| 640 | + } |
| 641 | + console.log('Re-rendering'); |
| 642 | + return thisContext._updateDom(element, tag, attrs, callback); |
| 643 | + } |
| 644 | + return; |
| 645 | + } |
617 | 646 | callback(error || err);
|
618 | 647 | });
|
619 | 648 | }
|
|
0 commit comments