Skip to content

Commit

Permalink
Injected reference fix
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxenko committed Mar 29, 2017
1 parent bb500c6 commit b55bddf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/cream.js
Expand Up @@ -44,7 +44,7 @@ Cream.prototype.get = function(name) {
* It is property function
*/
if (ref && typeof ref === 'object' && ref.isProperty === true) {
return ref.fn.call(this);
return ref.fn.call(ref.parent);
}

return ref;
Expand Down Expand Up @@ -260,9 +260,14 @@ Cream.extend = function(obj) {
F[i] = typeof obj[i] === 'function' &&
!obj[i].isInjection ? obj[i].bind(F) : obj[i];


if (F[i] && typeof F[i] === 'object' && F[i].isObserver === true) {
F._addObserver(F[i]);
}

if (obj[i] && typeof obj[i] === 'object' && obj[i].isProperty) {
obj[i].parent = F;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "cakejs2",
"version": "0.1.0",
"version": "0.1.1",
"description": "Lightweight front-end framework with only best parts and features of most awesome frameworks.",
"main": "index.js",
"files": [
Expand Down
19 changes: 19 additions & 0 deletions tests/cake.test.js
Expand Up @@ -246,4 +246,23 @@ describe('Cake', function() {

expect(initSpy.calledOnce).to.be.true;
});

it('should handle injected props', function() {
cake.Cream.extend({
_namespace: 'routes.store',
getNum: function() {
return this.get('data')[1] * 2;
}.property(),
data: [ 1, 2, 3, 4]
});

var Component = cake.Cream.extend({
store: cake.inject('routes.store'),
test: function() {
return this.get('store.getNum');
}
});

expect(Component.test()).to.be.equal(4);
});
});

0 comments on commit b55bddf

Please sign in to comment.