From bccf7ba2c654dbdc4097849a540a4effdc4259e2 Mon Sep 17 00:00:00 2001 From: Joscha Rohmann Date: Tue, 6 Sep 2016 23:47:13 +0200 Subject: [PATCH] Added custom debug messages for async view init, wrong []-observable-reset and usage of not comment-ready data-queries in comments. --- src/mvc/Application.js | 8 ++++++++ src/query/DomQuery.js | 4 +++- src/query/observable.js | 11 +++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/mvc/Application.js b/src/mvc/Application.js index 1aa7b1e..b638c10 100644 --- a/src/mvc/Application.js +++ b/src/mvc/Application.js @@ -261,6 +261,14 @@ define([ if (arguments.length == 1) { return this._views[name]; } + + if (this._started) { + // @if DEBUG + blocks.debug.throwMessage('Views can not be constructed / added after the application has been started. Try to add your views sync.', __DEBUG_METHOD, 'Error'); + // @endif + return; + } + if (blocks.isString(prototype)) { this._viewPrototypes[prototype] = this._createView(nestedViewPrototype); nestedViewPrototype.options.parentView = name; diff --git a/src/query/DomQuery.js b/src/query/DomQuery.js index 13f9025..3d4f77b 100644 --- a/src/query/DomQuery.js +++ b/src/query/DomQuery.js @@ -216,7 +216,9 @@ define([ if (VirtualElement.Is(element)) { if (VirtualComment.Is(element) && !method.supportsComments) { - // TODO: Should throw debug message + // @if DEBUG + blocks.debug.throwMessage('data-query ' + methods[i].name + ' does not support to be executed as on a comment.', blocks.debug.queries[methods[i].name], 'Error'); + // @endif continue; } diff --git a/src/query/observable.js b/src/query/observable.js index d82b7aa..544597a 100644 --- a/src/query/observable.js +++ b/src/query/observable.js @@ -37,9 +37,9 @@ define([ } else if (!blocks.equals(value, currentValue, false) && Events.trigger(observable, 'changing', value, currentValue) !== false) { observable.update = blocks.noop; if (!observable._dependencyType) { - if (blocks.isArray(currentValue) && blocks.isArray(value) && observable.reset) { + if (blocks.isArray(currentValue) && (blocks.isArray(value) || !value) && observable.reset) { observable.reset(value); - } else { + } else if (!blocks.isArray(currentValue) && !observable.reset) { observable.__value__ = value; } } else if (observable._dependencyType == 2) { @@ -368,6 +368,13 @@ define([ array = blocks.unwrap(array); + if (!blocks.isArray(array) && !!array) { + //@if DEBUG + blocks.debug.throwMessage('Array-Observables can not be reseted to a non array type! Reset got aborted.', __DEBUG_METHOD, 'Warning'); + //@endif + return; + } + var current = this.__value__; var chunkManager = this._chunkManager; var addCount = Math.max(array.length - current.length, 0);