Skip to content

Commit

Permalink
Merge branch 'release/0.4.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
dcrockwell committed Aug 29, 2016
2 parents 42fbe4d + 6be1775 commit 2991f08
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 1 deletion.
12 changes: 12 additions & 0 deletions es5/lib/component/propertyCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var PropertyCollection = function () {
_.merged = false;
_.flat = false;
_.filters = [];
_.thens = [];

this.properties = {};

Expand Down Expand Up @@ -68,6 +69,11 @@ var PropertyCollection = function () {
} else {
_this.properties[propertyName] = newValue;
}

_.thens.forEach(function (then) {
then(newValue);
});

return parentLink;
} else {
return _this.properties[propertyName];
Expand Down Expand Up @@ -98,6 +104,12 @@ var PropertyCollection = function () {
(0, _incognito2.default)(this).filters.push(filterFunction);
return this;
}
}, {
key: "then",
value: function then(thenFunction) {
(0, _incognito2.default)(this).thens.push(thenFunction);
return this;
}
}, {
key: "isAggregate",
get: function get() {
Expand Down
57 changes: 57 additions & 0 deletions es5/spec/component/component.properties.then.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _component = require("../../lib/component/component.js");

var _component2 = _interopRequireDefault(_component);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var Numbers = function (_Component) {
_inherits(Numbers, _Component);

function Numbers() {
_classCallCheck(this, Numbers);

return _possibleConstructorReturn(this, Object.getPrototypeOf(Numbers).apply(this, arguments));
}

_createClass(Numbers, [{
key: "initialize",
value: function initialize() {
var _this2 = this;

this.results = [];
this.returnValue = this.properties("values").aggregate.then(function (value) {
_this2.results.push(value);
});
}
}]);

return Numbers;
}(_component2.default);

describe(".properties.then(thenFunction)", function () {
var numbers = void 0;

beforeEach(function () {
numbers = new Numbers();
});

it("should return this when setting to enable chaining", function () {
var propertyCollection = numbers.propertyCollections()[0];
numbers.returnValue.should.eql(propertyCollection);
});

it("should call .then each time the property has a value set", function () {
numbers.values("1").values("2").values("3");
numbers.results.should.eql(["1", "2", "3"]);
});
});
11 changes: 11 additions & 0 deletions es6/lib/component/propertyCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default class PropertyCollection {
_.merged = false;
_.flat = false;
_.filters = [];
_.thens = [];

this.properties = {};

Expand Down Expand Up @@ -43,6 +44,11 @@ export default class PropertyCollection {
} else {
this.properties[propertyName] = newValue;
}

_.thens.forEach(then => {
then(newValue);
});

return parentLink;
} else {
return this.properties[propertyName];
Expand Down Expand Up @@ -115,6 +121,11 @@ export default class PropertyCollection {
return this;
}

then(thenFunction) {
privateData(this).thens.push(thenFunction);
return this;
}

get merged() {
const _ = privateData(this);

Expand Down
33 changes: 33 additions & 0 deletions es6/spec/component/component.properties.then.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Component from "../../lib/component/component.js";

class Numbers extends Component {
initialize() {
this.results = [];
this.returnValue = this.properties("values")
.aggregate
.then(value => {
this.results.push(value);
});
}
}

describe(".properties.then(thenFunction)", () => {
let numbers;

beforeEach(() => {
numbers = new Numbers();
});

it("should return this when setting to enable chaining", () => {
const propertyCollection = numbers.propertyCollections()[0];
numbers.returnValue.should.eql(propertyCollection);
});

it("should call .then each time the property has a value set", () => {
numbers
.values("1")
.values("2")
.values("3");
numbers.results.should.eql([ "1", "2", "3" ]);
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mrt",
"version": "0.4.2",
"version": "0.4.3",
"description": "Helps build expressive chained interfaces.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 2991f08

Please sign in to comment.