Skip to content

Commit

Permalink
Merge pull request #55 from imweb/1.0.0
Browse files Browse the repository at this point in the history
build
  • Loading branch information
miniflycn committed Aug 10, 2015
2 parents 8890682 + e5d8970 commit 194b9b7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 231 deletions.
78 changes: 3 additions & 75 deletions dist/Q.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Q.js v0.5.6
* Q.js v1.0.0
* Inspired from vue.js
* (c) 2015 Daniel Yang
* Released under the MIT License.
Expand Down Expand Up @@ -1402,28 +1402,14 @@ return /******/ (function(modules) { // webpackBootstrap
el = this.el,
// component reference
ref = el.getAttribute('q-ref') || false,
key = el.getAttribute('q-with') || '',
namespace = this.namespace,
target = _.get(namespace, key),
data = vm.data(target),
Child = vm.constructor.require(name),
mergeTarget = Child.options.data,
data = Child.options.data,
options,
childVm;

// merge data
mergeTarget &&
data ?
Object.keys(mergeTarget).forEach(function (key) {
key in data ||
data.$set(key, mergeTarget[key]);
}) :
(data = vm.data(target, mergeTarget));

options = {
el: el,
// TODO maybe need to remove
data: data.$get(),
data: data,
_parent: vm
};

Expand All @@ -1438,64 +1424,6 @@ return /******/ (function(modules) { // webpackBootstrap
(vm.$[ref] = [refs, childVm]) :
(vm.$[ref] = childVm);
}();

// prevent child vm data change to trigger parent vm
var _preventChild = false,
// prevent parent vm data change to trigger child vm
_preventParent = false,
// data cache
dataCache;

// first trigger
target &&
vm.$watch(target, function (value, oldVal, patch) {
if (_preventParent && target === _preventParent) return;
// cache the data when target change
dataCache = value;
});

// second trigger
vm.$on('datachange', function (prop, value, oldVal, patch) {
if (this === childVm) {
if (_preventChild && prop === _preventChild) {

_preventChild = false;
} else {
var parentProp = _.get(target, prop);
// prevent parent datachange
_preventParent = parentProp;
patch ?
vm[parentProp][patch.method].apply(vm[parentProp], patch.args) :
_setProp(vm, parentProp, value);
}
} else if (this === vm) {
if (_preventParent) {
// this prevent this time
_preventParent = false;
// change data need sync
} else if (!target || (prop !== target && !prop.indexOf(target))) {
var start = target.length,
childProp;

start && (start += 1);
childProp = prop.substring(start, prop.length);
// prevent child datachange
_preventChild = childProp;

patch ?
childVm[childProp][patch.method].apply(childVm[childProp], patch.args) :
_setProp(childVm, childProp, value);
// maybe not need sync, check data cache if exist just sync
} else if (!target.indexOf(prop) && dataCache) {
// prevent child datachange
_preventChild = target;

childVm.$set(dataCache);
// clear the data cache
dataCache = undefined;
}
}
});
}
},
'if': {
Expand Down
Loading

0 comments on commit 194b9b7

Please sign in to comment.