Skip to content
This repository has been archived by the owner on Jan 13, 2018. It is now read-only.

deps: possibility to declare dependence without explicit including item #464

Merged
merged 6 commits into from
Oct 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions lib/techs/deps.js.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,15 @@ var Deps = exports.Deps = INHERIT({
var items = this.items,
targetKey = target.buildKey(),
itemKey = item.buildKey(),
itemByKey = items[itemKey],
deps;

if (!items[itemKey]) {
if(!itemByKey) {
items[itemKey] = item;
item.include && this.itemsByOrder.push(itemKey);
} else if(!itemByKey.include && item.include) {
// update `include` for existing item in case of adding of new item without `include: false`
itemByKey.include = true;
this.itemsByOrder.push(itemKey);
}

Expand Down Expand Up @@ -376,11 +381,13 @@ var Deps = exports.Deps = INHERIT({
var key = i.buildKey(),
ctxTech = ctx && ctx.item.tech || '';
if(!uniq.hasOwnProperty(key) || !uniq[key].hasOwnProperty(ctxTech)) {
(uniq[key] || (uniq[key] = {}))[ctxTech] = true;
var newCtx = ctx || i;
_this.forEach(fn, uniq, i.mustDeps, i);
fn.call(_this, i, newCtx);
_this.forEach(fn, uniq, i.shouldDeps, i);
if(i.include) { // include only items without `include: false`
(uniq[key] || (uniq[key] = {}))[ctxTech] = true;
var newCtx = ctx || i;
_this.forEach(fn, uniq, i.mustDeps, i);
fn.call(_this, i, newCtx);
_this.forEach(fn, uniq, i.shouldDeps, i);
}
}
}
});
Expand Down Expand Up @@ -497,7 +504,7 @@ var DepsItem = exports.DepsItem = INHERIT({
this.item = {};
this.extendByCtx({ item: item });
this.extendByCtx(ctx);

this.include = item.include !== false;
},

extendByCtx: function(ctx) {
Expand Down
38 changes: 30 additions & 8 deletions lib/techs/v2/deps.js.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,15 @@ var Deps = exports.Deps = INHERIT(/** @lends Deps.prototype */{
var items = this.items,
targetKey = target.buildKey(),
itemKey = item.buildKey(),
itemByKey = items[itemKey],
deps;

if (!items[itemKey]) {
if(!itemByKey) {
items[itemKey] = item;
item.include && this.itemsByOrder.push(itemKey);
} else if(!itemByKey.include && item.include) {
// update `include` for existing item in case of adding of new item without `include: false`
itemByKey.include = true;
this.itemsByOrder.push(itemKey);
}

Expand Down Expand Up @@ -557,11 +562,13 @@ var Deps = exports.Deps = INHERIT(/** @lends Deps.prototype */{
var key = i.buildKey(),
ctxTech = ctx && ctx.item.tech || '';
if(!uniq.hasOwnProperty(key) || !uniq[key].hasOwnProperty(ctxTech)) {
(uniq[key] || (uniq[key] = {}))[ctxTech] = true;
var newCtx = ctx || i;
_this.forEach(fn, uniq, i.mustDeps, i);
fn.call(_this, i, newCtx);
_this.forEach(fn, uniq, i.shouldDeps, i);
if(i.include) { // include only items without `include: false`
(uniq[key] || (uniq[key] = {}))[ctxTech] = true;
var newCtx = ctx || i;
_this.forEach(fn, uniq, i.mustDeps, i);
fn.call(_this, i, newCtx);
_this.forEach(fn, uniq, i.shouldDeps, i);
}
}
}
});
Expand Down Expand Up @@ -604,7 +611,7 @@ var Deps = exports.Deps = INHERIT(/** @lends Deps.prototype */{
var _this = this, uniq = {}, res = [];
_filter();
return res;

function _filter(itemsByOrder,ctx){
(itemsByOrder||_this.items[''].shouldDeps).forEach(function(item){
if(item = _this.items[item]){
Expand Down Expand Up @@ -677,7 +684,11 @@ var Deps = exports.Deps = INHERIT(/** @lends Deps.prototype */{
* @returns {Object}
*/
serializeFull: function() {
return this.items;
var result = {};
for(var item in this.items){
result[item] = this.items[item].serializeFull();
}
return result;
},

/**
Expand All @@ -700,6 +711,7 @@ var DepsItem = exports.DepsItem = INHERIT({
this.item = {};
this.extendByCtx({ item: item });
this.extendByCtx(ctx);
this.include = item.include !== false;
},

extendByCtx: function(ctx) {
Expand Down Expand Up @@ -775,6 +787,16 @@ var DepsItem = exports.DepsItem = INHERIT({

while(k = ks.shift()) this.item[k] && (res[k] = this.item[k]);
if(res.block) return res;
},

serializeFull: function() {
var res = {};
for (var key in this) {
if (this.hasOwnProperty(key)) {
res[key] = this[key];
}
}
return res;
}

});
Expand Down
Loading