Skip to content

Commit

Permalink
0.3.4 release
Browse files Browse the repository at this point in the history
  • Loading branch information
astoilkov committed Oct 16, 2015
1 parent a09f704 commit c552b7d
Show file tree
Hide file tree
Showing 15 changed files with 479 additions and 284 deletions.
144 changes: 89 additions & 55 deletions dist/blocks-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
return value;
};

blocks.version = '0.3.3';
blocks.version = '0.3.4';
blocks.core = core;

/**
Expand Down Expand Up @@ -4034,7 +4034,8 @@ return result;
// if element is not defined then treat it as expression
if (!element) {
currentData = data[id] = {
id: id
id: id,
observables: {}
};
} else {
currentData = data[id] = {
Expand Down Expand Up @@ -4074,11 +4075,21 @@ return result;
if (currentData && (!currentData.haveData || force)) {
blocks.each(currentData.observables, function (value) {
for (var i = 0; i < value._elements.length; i++) {
if (value._elements[i].elementId == data.id) {
if (value._elements[i].elementId == currentData.id) {
value._elements.splice(i, 1);
i--;
}
}

if (value._expressionKeys[currentData.id]) {
for (i = 0; i < value._expressions.length; i++) {
if (value._expressions[i].elementId == currentData.id) {
value._expressions.splice(i, 1);
i--;
}
}
value._expressionKeys[currentData.id] = null;
}
});
data[id] = undefined;
if (VirtualElement.Is(element)) {
Expand Down Expand Up @@ -4543,6 +4554,8 @@ return result;
observable._expressionKeys[elementData.id] = true;
observable._expressions.push(expressionObj);
}

elementData.observables[observable.__id__ + (attributeName || 'expression') + '[' + expression + ']'] = observable;
});
}
if (!attributeName) {
Expand Down Expand Up @@ -5124,7 +5137,7 @@ return result;
var value;

if (this._tagName == 'option' && this._parent._values) {
if (state) {
if (state && typeof state.attributes.value !== 'undefined') {
state.attributes.selected = this._parent._values[state.attributes.value] ? 'selected' : null;
} else {
attributes.selected = this._parent._values[attributes.value] ? 'selected' : null;
Expand Down Expand Up @@ -5164,6 +5177,11 @@ return result;
var expression;

blocks.each(this._attributes, function (attributeValue, attributeName) {
if(!attributeValue) {
// In Serverside rendering, some attributes will be set to null in some cases
return;
}

if (!each && serverData && serverData[dataId + attributeName]) {
expression = Expression.Create(serverData[dataId + attributeName], attributeName);
} else {
Expand Down Expand Up @@ -7020,13 +7038,15 @@ return result;
if (!events || !callbacks) {
return;
}
var element = this;
var context = blocks.context(this);
var thisArg;

callbacks = blocks.toArray(callbacks);

var element = this;
var handler = function (e) {
var context = blocks.context(this);
var thisArg = context.$template || context.$view || context.$root;
context = blocks.context(this) || context;
thisArg = context.$template || context.$view || context.$root;
blocks.each(callbacks, function (callback) {
callback.call(thisArg, e, args);
});
Expand Down Expand Up @@ -7302,7 +7322,7 @@ return result;
observable._chunkManager = new ChunkManager(observable);
} else if (blocks.isFunction(initialValue)) {
observable._dependencyType = 1; // Function dependecy
} else if (initialValue && blocks.isFunction(initialValue.get) && blocks.isFunction(initialValue.set)) {
} else if (initialValue && !initialValue.__Class__ && blocks.isFunction(initialValue.get) && blocks.isFunction(initialValue.set)) {
observable._dependencyType = 2; // Custom object
}

Expand Down Expand Up @@ -7395,6 +7415,8 @@ return result;
var element;
var offset;
var value;
var isProperty;
var propertyName;

blocks.eachRight(this._expressions, function updateExpression(expression) {
element = expression.element;
Expand All @@ -7416,9 +7438,16 @@ return result;
offset = expression.length - value.length;
expression.length = value.length;

isProperty = dom.props[expression.attr];
propertyName = expression.attr ? dom.propFix[expression.attr.toLowerCase()] || expression.attr : null;

if (element) {
if (expression.attr) {
element.setAttribute(expression.attr, Expression.GetValue(context, null, expression.entire));
if(isProperty) {
element[propertyName] = Expression.GetValue(context, null, expression.entire);
} else {
element.setAttribute(expression.attr, Expression.GetValue(context, null, expression.entire));
}
} else {
if (element.nextSibling) {
element = element.nextSibling;
Expand Down Expand Up @@ -10336,40 +10365,26 @@ return result;
var key;
var value;

if (prototype.__used__) {
for (key in prototype) {
value = prototype[key];
if (Property.Is(value)) {
continue;
}

if (blocks.isObservable(value)) {
// clone the observable and also its value by passing true to the clone method
object[key] = value.clone(true);
object[key].__context__ = object;
} else if (blocks.isFunction(value)) {
object[key] = blocks.bind(value, object);
} else if (Model.prototype.isPrototypeOf(value)) {
object[key] = value.clone(true);
} else if (blocks.isObject(value) && !blocks.isPlainObject(value)) {
object[key] = blocks.clone(value, true);
} else {
object[key] = blocks.clone(value, true);
}
for (key in prototype) {
value = prototype[key];
if (Property.Is(value)) {
continue;
}
} else {
for (key in prototype) {
value = prototype[key];
if (blocks.isObservable(value)) {
value.__context__ = object;
} else if (blocks.isFunction(value)) {
object[key] = blocks.bind(value, object);
object[key].unbound = value;
}

if (blocks.isObservable(value)) {
// clone the observable and also its value by passing true to the clone method
object[key] = value.clone(true);
object[key].__context__ = object;
} else if (blocks.isFunction(value)) {
object[key] = blocks.bind(value, object);
} else if (Model.prototype.isPrototypeOf(value)) {
object[key] = value.clone(true);
} else if (blocks.isObject(value) && !blocks.isPlainObject(value)) {
object[key] = blocks.clone(value, true);
} else {
object[key] = blocks.clone(value, true);
}
}

prototype.__used__ = true;
}

var routeStripper = /^[#\/]|\s+$/g;
Expand Down Expand Up @@ -10853,25 +10868,23 @@ return result;
/**
* @namespace View
*/
function View(application, parentView, prototype) {
function View(application, parentView) {
var _this = this;
var options = this.options;

clonePrototype(prototype, this);

this._bindContext();
this._views = [];
this._application = application;
this._parentView = parentView || null;
this._initCalled = false;
this._html = undefined;

this.loading = blocks.observable(false);
this.isActive = blocks.observable(!blocks.has(options, 'route'));
this.isActive = blocks.observable(!blocks.has(this.options, 'route'));
this.isActive.on('changing', function (oldValue, newValue) {
_this._tryInitialize(newValue);
});

if (options.preload || this.isActive()) {
if (this.options.preload || this.isActive()) {
this._load();
}
}
Expand Down Expand Up @@ -10998,6 +11011,21 @@ return result;
this._application.navigateTo(view, params);
},

_bindContext: function () {
var key;
var value;

for (key in this) {
value = this[key];

if (blocks.isObservable(value)) {
value.__context__ = this;
} else if (blocks.isFunction(value)) {
this[key] = blocks.bind(value, this);
}
}
},

_tryInitialize: function (isActive) {
if (!this._initialized && isActive) {
if (this.options.url && !this._html) {
Expand Down Expand Up @@ -11381,25 +11409,31 @@ return result;
},

_viewsReady: function (views) {
var callReady = this._callReady;

blocks.each(views, function (view) {
if (view.ready !== blocks.noop) {
if (view.isActive()) {
view.ready();
callReady(view);
} else {
view.isActive.once('change', function () {
if (view.loading()) {
view.loading.once('change', function () {
view.ready();
});
} else {
view.ready();
}
callReady(view);
});
}
}
});
},

_callReady: function (view) {
if (view.loading()) {
view.loading.once('change', function () {
view.ready();
});
} else {
view.ready();
}
},

_urlChange: function (data) {
var _this = this;
var currentView = this._currentView;
Expand Down Expand Up @@ -11441,7 +11475,7 @@ return result;
// }

return blocks.inherit(View, function (application, parentView) {
this._super([application, parentView, prototype]);
this._super([application, parentView]);
}, prototype);
},

Expand Down
Loading

0 comments on commit c552b7d

Please sign in to comment.