Skip to content

Commit

Permalink
Merge branch 'release/0.4.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
dcrockwell committed Aug 30, 2016
2 parents 9b73791 + c03bc67 commit 25c51fc
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 51 deletions.
2 changes: 1 addition & 1 deletion es5/lib/component/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ var Link = function () {
}

if (_.then) {
_.then(instance);
_.then.call(this.parentLink, instance);
}

return instance;
Expand Down
6 changes: 5 additions & 1 deletion es5/lib/component/propertyCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ var PropertyCollection = function () {
}

_.thens.forEach(function (then) {
then(newValue);
if (_.multi) {
then.apply(_.parentLink, newValue);
} else {
then.call(_.parentLink, newValue);
}
});

return parentLink;
Expand Down
12 changes: 9 additions & 3 deletions es5/spec/component/component.link.then.sync.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
describe("component.link.then", function () {
var person = void 0,
thought = void 0,
thenFunction = void 0;
thenFunction = void 0,
actualContext = void 0;

var Person = function (_Component) {
_inherits(Person, _Component);
Expand Down Expand Up @@ -55,9 +56,10 @@ describe("component.link.then", function () {
}(_component2.default);

beforeEach(function () {
thenFunction = _sinon2.default.spy(function (component) {
thenFunction = function thenFunction(component) {
actualContext = this;
component.thenCalledWith = component;
});
};

person = new Person();
thought = person.thought();
Expand All @@ -66,4 +68,8 @@ describe("component.link.then", function () {
it("should call then with the newly instantiated component", function () {
thought.thenCalledWith.should.eql(thought);
});

it("should be called with the correct context", function () {
actualContext.should.eql(person);
});
});
65 changes: 65 additions & 0 deletions es5/spec/component/component.properties.then.multi.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"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; }

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

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() {
returnValue = this.properties("values").multi.aggregate.flat.then(function (value) {
actualContext = this;
results.push(value);
});
}
}]);

return Numbers;
}(_component2.default);

beforeEach(function () {
actualContext = null;
results = [];
numbers = new Numbers();
});

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

it("should call .then each time the property has a value set", function () {
numbers.values("1").values("2").values("3");
results.should.eql(["1", "2", "3"]);
});

it("should be called with the correct context", function () {
numbers.values("1");
actualContext.should.eql(numbers);
});
});
54 changes: 31 additions & 23 deletions es5/spec/component/component.properties.then.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,52 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen

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);
describe(".properties.then(thenFunction)", function () {
var numbers = void 0,
actualContext = void 0,
results = void 0,
returnValue = void 0;

return _possibleConstructorReturn(this, Object.getPrototypeOf(Numbers).apply(this, arguments));
}
var Numbers = function (_Component) {
_inherits(Numbers, _Component);

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

this.results = [];
this.returnValue = this.properties("values").aggregate.then(function (value) {
_this2.results.push(value);
});
return _possibleConstructorReturn(this, Object.getPrototypeOf(Numbers).apply(this, arguments));
}
}]);

return Numbers;
}(_component2.default);
_createClass(Numbers, [{
key: "initialize",
value: function initialize() {
returnValue = this.properties("value").then(function (value) {
actualContext = this;
results.push(value);
});
}
}]);

describe(".properties.then(thenFunction)", function () {
var numbers = void 0;
return Numbers;
}(_component2.default);

beforeEach(function () {
actualContext = null;
results = [];
numbers = new Numbers();
});

it("should return this when setting to enable chaining", function () {
var propertyCollection = numbers.propertyCollections()[0];
numbers.returnValue.should.eql(propertyCollection);
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"]);
numbers.value("1").value("2").value("3");
results.should.eql(["1", "2", "3"]);
});

it("should be called with the correct context", function () {
numbers.value("1");
actualContext.should.eql(numbers);
});
});
2 changes: 1 addition & 1 deletion es6/lib/component/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default class Link {
}

if (_.then) {
_.then(instance);
_.then.call(this.parentLink, instance);
}

return instance;
Expand Down
6 changes: 5 additions & 1 deletion es6/lib/component/propertyCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export default class PropertyCollection {
}

_.thens.forEach(then => {
then(newValue);
if (_.multi) {
then.apply(_.parentLink, newValue);
} else {
then.call(_.parentLink, newValue);
}
});

return parentLink;
Expand Down
12 changes: 9 additions & 3 deletions es6/spec/component/component.link.then.sync.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import sinon from "sinon";
describe("component.link.then", () => {
let person,
thought,
thenFunction;
thenFunction,
actualContext;

class Person extends Component {
initialize() {
Expand All @@ -17,9 +18,10 @@ describe("component.link.then", () => {
class Thought extends Component {}

beforeEach(() => {
thenFunction = sinon.spy(component => {
thenFunction = function (component) {
actualContext = this;
component.thenCalledWith = component;
});
};

person = new Person();
thought = person.thought();
Expand All @@ -28,4 +30,8 @@ describe("component.link.then", () => {
it("should call then with the newly instantiated component", () => {
thought.thenCalledWith.should.eql(thought);
});

it("should be called with the correct context", () => {
actualContext.should.eql(person);
});
});
43 changes: 43 additions & 0 deletions es6/spec/component/component.properties.then.multi.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Component from "../../lib/component/component.js";

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

class Numbers extends Component {
initialize() {
returnValue = this.properties("values")
.multi.aggregate.flat
.then(function (value) {
actualContext = this;
results.push(value);
});
}
}

beforeEach(() => {
actualContext = null;
results = [];
numbers = new Numbers();
});

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

it("should call .then each time the property has a value set", () => {
numbers
.values("1")
.values("2")
.values("3");
results.should.eql([ "1", "2", "3" ]);
});

it("should be called with the correct context", () => {
numbers.values("1");
actualContext.should.eql(numbers);
});
});
43 changes: 26 additions & 17 deletions es6/spec/component/component.properties.then.spec.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
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;
let numbers,
actualContext,
results,
returnValue;

class Numbers extends Component {
initialize() {
returnValue = this.properties("value")
.then(function (value) {
actualContext = this;
results.push(value);
});
}
}

beforeEach(() => {
actualContext = null;
results = [];
numbers = new Numbers();
});

it("should return this when setting to enable chaining", () => {
const propertyCollection = numbers.propertyCollections()[0];
numbers.returnValue.should.eql(propertyCollection);
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" ]);
.value("1")
.value("2")
.value("3");
results.should.eql([ "1", "2", "3" ]);
});

it("should be called with the correct context", () => {
numbers.value("1");
actualContext.should.eql(numbers);
});
});
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.4",
"version": "0.4.5",
"description": "Helps build expressive chained interfaces.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 25c51fc

Please sign in to comment.