Skip to content

Commit

Permalink
Release 1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
miniflycn committed Nov 23, 2015
1 parent 91c66dd commit c63a437
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 18 deletions.
10 changes: 7 additions & 3 deletions dist/Q.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Q.js v1.0.4
* Q.js v1.0.5
* Inspired from vue.js
* (c) 2015 Daniel Yang
* Released under the MIT License.
Expand Down Expand Up @@ -975,8 +975,12 @@ return /******/ (function(modules) { // webpackBootstrap
/**
* get the parent of the data
*/
$up: function () {
return this._up;
$up: function (num) {
num = num || 1;
for (var src = this; num--;) {
src = src['_up'];
}
return src;
},
/**
* set the value of the key
Expand Down
4 changes: 2 additions & 2 deletions dist/Q.min.js

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions dist/Q.native.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Q.js v1.0.4
* Q.js v1.0.5
* Inspired from vue.js
* (c) 2015 Daniel Yang
* Released under the MIT License.
Expand Down Expand Up @@ -1048,8 +1048,12 @@ return /******/ (function(modules) { // webpackBootstrap
/**
* get the parent of the data
*/
$up: function () {
return this._up;
$up: function (num) {
num = num || 1;
for (var src = this; num--;) {
src = src['_up'];
}
return src;
},
/**
* set the value of the key
Expand Down
4 changes: 2 additions & 2 deletions dist/Q.native.min.js

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions dist/Q.zepto.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Q.js v1.0.4
* Q.js v1.0.5
* Inspired from vue.js
* (c) 2015 Daniel Yang
* Released under the MIT License.
Expand Down Expand Up @@ -998,8 +998,12 @@ return /******/ (function(modules) { // webpackBootstrap
/**
* get the parent of the data
*/
$up: function () {
return this._up;
$up: function (num) {
num = num || 1;
for (var src = this; num--;) {
src = src['_up'];
}
return src;
},
/**
* set the value of the key
Expand Down
4 changes: 2 additions & 2 deletions dist/Q.zepto.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Q.js",
"version": "1.0.4",
"version": "1.0.5",
"description": "fake-MVVM library",
"main": "dist/Q.js",
"scripts": {
Expand Down
8 changes: 6 additions & 2 deletions src/core/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ _.extend(Data.prototype, {
/**
* get the parent of the data
*/
$up: function () {
return this._up;
$up: function (num) {
num = num || 1;
for (var src = this; num--;) {
src = src['_up'];
}
return src;
},
/**
* set the value of the key
Expand Down
48 changes: 48 additions & 0 deletions tests/spec/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,54 @@ module.exports = function (Q) {
}
});
});

it('should able to use .$up to get the up data', function () {
var vm = new Q({
el: null,
data: {
a: {
b: {
c: 'hello'
}
}
}
});

vm.a.b.$up().should.equal(vm.a);
vm.a.b.$up().should.equal(vm.a.b.$up(1));
vm.a.b.$up(2).should.equal(vm);
});

it('should able to use .$key to get a data key', function () {
var vm = new Q({
el: null,
data: {
a: {
b: {
c: 'hello'
}
}
}
});

vm.a.b.$key().should.equal('b');
vm.a.$key().should.equal('a');
});

it('should able to use .$namespace to get a namespace in the model', function () {
var vm = new Q({
el: null,
data: {
a: {
b: {
c: 'hello'
}
}
}
});

vm.a.b.$namespace().should.equal('a.b');
});
});

};

0 comments on commit c63a437

Please sign in to comment.