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 #463

Merged
merged 5 commits into from
Oct 16, 2013
Merged
Show file tree
Hide file tree
Changes from 3 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
22 changes: 14 additions & 8 deletions lib/techs/deps.js.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,14 @@ var Deps = exports.Deps = INHERIT({
add: function(target, depsType, item) {
var items = this.items,
targetKey = target.buildKey(),
itemKey = item.buildKey();
itemKey = item.buildKey(),
itemByKey = items[itemKey];

if(!items[itemKey]) {
if(!itemByKey) {
items[itemKey] = item;
item.include && this.itemsByOrder.push(itemKey);
} else if(!itemByKey.include && item.include) {
itemByKey.include = true;
this.itemsByOrder.push(itemKey);
}

Expand Down Expand Up @@ -300,11 +304,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, newCtx);
fn.call(_this, i, newCtx);
_this.forEach(fn, uniq, i.shouldDeps, newCtx);
if(i.include) {
(uniq[key] || (uniq[key] = {}))[ctxTech] = true;
var newCtx = ctx || i;
_this.forEach(fn, uniq, i.mustDeps, newCtx);
fn.call(_this, i, newCtx);
_this.forEach(fn, uniq, i.shouldDeps, newCtx);
}
}
}
});
Expand Down Expand Up @@ -364,7 +370,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
21 changes: 14 additions & 7 deletions lib/techs/v2/deps.js.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,14 @@ var Deps = exports.Deps = INHERIT({
add: function(target, depsType, item) {
var items = this.items,
targetKey = target.buildKey(),
itemKey = item.buildKey();
itemKey = item.buildKey(),
itemByKey = items[itemKey];

if(!items[itemKey]) {
if(!itemByKey) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Что происходит в этом блоке? Добавьте комментарий, пожалуйста.

items[itemKey] = item;
item.include && this.itemsByOrder.push(itemKey);
} else if(!itemByKey.include && item.include) {
itemByKey.include = true;
this.itemsByOrder.push(itemKey);
}

Expand Down Expand Up @@ -414,11 +418,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, newCtx);
fn.call(_this, i, newCtx);
_this.forEach(fn, uniq, i.shouldDeps, newCtx);
if(i.include) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавьте комментариев, пожалуйста

(uniq[key] || (uniq[key] = {}))[ctxTech] = true;
var newCtx = ctx || i;
_this.forEach(fn, uniq, i.mustDeps, newCtx);
fn.call(_this, i, newCtx);
_this.forEach(fn, uniq, i.shouldDeps, newCtx);
}
}
}
});
Expand Down Expand Up @@ -478,6 +484,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
55 changes: 45 additions & 10 deletions test/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,29 @@ describe('Deps', function() {

});

describe('include: false', function() {

it('block', assertDepsParse(
[
{
block: 'b1',
shouldDeps: [
{ block: 'b2', include: false },
{ block: 'b3', include: false }
],
mustDeps: [
{ block: 'b4', include: false },
{ block: 'b5', include: false }
]
},
{ block: 'b3' },
{ block: 'b4' }
],
{ '': { '': [ { block: 'b4' }, { block: 'b1' }, { block: 'b3' } ] } }
));

});

});

describe('serialize:', function() {
Expand All @@ -205,9 +228,13 @@ describe('Deps', function() {

describe('clone', function() {

var deps1 = new Deps().parse([{ block: 'b1', bla: 1 }, 'b2']),
deps2 = deps1.clone(),
var deps1, deps2, deps;

beforeEach(function(){
deps1 = new Deps().parse([{ block: 'b1', bla: 1 }, 'b2']);
deps2 = deps1.clone();
deps = [deps1, deps2];
});

it('.items', function() {
assert.deepEqual(deps[1].items, deps[0].items);
Expand All @@ -221,24 +248,28 @@ describe('Deps', function() {

describe('subtract', function() {

var deps1 = new DEPS.Deps().parse([
var deps1, deps2, deps3;

beforeEach(function() {
deps1 = new DEPS.Deps().parse([
{ block: 'b1' },
{ block: 'b2' },
{ block: 'b3' },
{ block: 'b5' }
]),
]);

deps2 = new DEPS.Deps().parse([
{ block: 'b1' },
{ block: 'b3' },
{ block: 'b4' }
]),
]);

deps3 = new DEPS.Deps().parse([
{ block: 'b5' }
]);

deps1.subtract(deps2).subtract(deps3);
deps1.subtract(deps2).subtract(deps3);
});

it('works correctly', function() {
assert.deepEqual(deps1.serialize(), {
Expand All @@ -252,26 +283,30 @@ describe('Deps', function() {

describe('intersect', function() {

var deps1 = new DEPS.Deps().parse([
var deps1, deps2, deps3;

beforeEach(function() {
deps1 = new DEPS.Deps().parse([
{ block: 'b1' },
{ block: 'b2' },
{ block: 'b3' },
{ block: 'b5' }
]),
]);

deps2 = new DEPS.Deps().parse([
{ block: 'b3' },
{ block: 'b1' },
{ block: 'b4' }
]),
]);

deps3 = new DEPS.Deps().parse([
{ block: 'b3' },
{ block: 'b6' },
{ block: 'b1' }
]);

deps1.intersect(deps2).intersect(deps3);
deps1.intersect(deps2).intersect(deps3);
});

it('works correctly', function() {
assert.deepEqual(deps1.serialize(), {
Expand Down
Loading