Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
Added feature to remove an array of items from an ObjectResolver.
Browse files Browse the repository at this point in the history
  • Loading branch information
ronelliott committed Aug 10, 2015
1 parent 5ed163f commit a06e697
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
10 changes: 8 additions & 2 deletions reflekt.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,16 @@ function ObjectResolver(items) {

/**
removes an item with the given name from the ObjectResolver
@param {String} name - the name of the item to remove
@param {String|Array} name - the name(s) of the item to remove
*/
function remove(name) {
delete items[name];
if (isArray(name)) {
name.forEach(function(name) {
delete items[name];
});
} else {
delete items[name];
}
}

resolve.items = items;
Expand Down
38 changes: 38 additions & 0 deletions test/ObjectResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,44 @@ describe('ObjectResolver', function() {
}
});

it('should remove all items in an array', function() {
var that = this;

this.resolver.add({
bar: true,
dar: true,
zar: true
});

check([
'bar',
'dar',
'zar'
], true);

this.resolver.remove([
'bar',
'dar',
'zar'
]);

check([
'bar',
'dar',
'zar'
], false);

function check(values, shouldExist) {
values.forEach(function(name) {
if (shouldExist) {
should(that.resolver(name)).equal(true);
} else {
should(that.resolver(name)).equal(undefined);
}
});
}
});

it('should store lifetimes values when adding an item', function() {
this.resolver.add('foo', 'foo', 1);
this.resolver.lifetimes.foo.should.equal(1);
Expand Down

0 comments on commit a06e697

Please sign in to comment.