Skip to content

Commit

Permalink
bug fix for linked methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dcrockwell committed Sep 10, 2016
1 parent 6a1114e commit fd68543
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 18 deletions.
20 changes: 11 additions & 9 deletions es5/lib/component/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ var Link = function () {
}, {
key: "apply",
value: function apply() {
var _ = (0, _incognito2.default)(this);

for (var _len = arguments.length, newArguments = Array(_len), _key = 0; _key < _len; _key++) {
newArguments[_key] = arguments[_key];
}

console.log({ newArguments: newArguments });
var _ = (0, _incognito2.default)(this);
_.useArguments = _.useArguments.concat(newArguments);
return this;
}
Expand Down Expand Up @@ -97,14 +97,16 @@ var Link = function () {
});

methodNames.forEach(function (propertyName) {
var propertyDescriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(_this2.parentLink), propertyName);
if (propertyDescriptor.value) {
propertyDescriptor.value = propertyDescriptor.value.bind(_this2.parentLink);
}
if (propertyDescriptor.get) {
propertyDescriptor.get = propertyDescriptor.get.bind(_this2.parentLink);
if (!instance[propertyName]) {
var propertyDescriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(_this2.parentLink), propertyName);
if (propertyDescriptor.value) {
propertyDescriptor.value = propertyDescriptor.value.bind(_this2.parentLink);
}
if (propertyDescriptor.get) {
propertyDescriptor.get = propertyDescriptor.get.bind(_this2.parentLink);
}
Object.defineProperty(instance, propertyName, propertyDescriptor);
}
Object.defineProperty(instance, propertyName, propertyDescriptor);
});

this.parentLink.links.all.forEach(function (link) {
Expand Down
12 changes: 11 additions & 1 deletion es5/spec/component/component.link.properties.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ var Person = function (_Component) {
this.link("arm", Arm);
this.link("pet", Pet);
}
}, {
key: "dna",
get: function get() {
return "abcdefg";
}
}]);

return Person;
Expand All @@ -49,7 +54,8 @@ var Arm = function (_Component2) {
_createClass(Arm, [{
key: "initialize",
value: function initialize(length) {
this.properties("length");
this.properties("length", "dna");
this.dna("dagca");
this.length(length);
}
}]);
Expand Down Expand Up @@ -90,6 +96,10 @@ describe("component.link.properties", function () {
person.arm().length(5).name().should.eql(name);
});

it("should be able to call overridden properties from a parent link", function () {
person.arm().dna("aabbagc").dna().should.eql("aabbagc");
});

it("should override identical parent properties", function () {
var petName = "Fluffy";
person.pet(petName).name().should.eql(petName);
Expand Down
7 changes: 6 additions & 1 deletion es5/spec/component/component.properties.then.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ describe(".properties.then(thenFunction)", function () {
});

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

numbers.value();

numbers.value("3");

results.should.eql(["1", "2", "3"]);
});

Expand Down
11 changes: 6 additions & 5 deletions es6/lib/component/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default class Link {
}

apply(...newArguments) {
console.log({ newArguments });
const _ = privateData(this);
_.useArguments = _.useArguments.concat(newArguments);
return this;
Expand Down Expand Up @@ -60,10 +59,12 @@ export default class Link {
});

methodNames.forEach(propertyName => {
const propertyDescriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.parentLink), propertyName);
if (propertyDescriptor.value) { propertyDescriptor.value = propertyDescriptor.value.bind(this.parentLink); }
if (propertyDescriptor.get) { propertyDescriptor.get = propertyDescriptor.get.bind(this.parentLink); }
Object.defineProperty(instance, propertyName, propertyDescriptor);
if (!instance[propertyName]) {
const propertyDescriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.parentLink), propertyName);
if (propertyDescriptor.value) { propertyDescriptor.value = propertyDescriptor.value.bind(this.parentLink); }
if (propertyDescriptor.get) { propertyDescriptor.get = propertyDescriptor.get.bind(this.parentLink); }
Object.defineProperty(instance, propertyName, propertyDescriptor);
}
});

this.parentLink.links.all.forEach(link => {
Expand Down
13 changes: 12 additions & 1 deletion es6/spec/component/component.link.properties.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ class Person extends Component {
this.link("arm", Arm);
this.link("pet", Pet);
}

get dna() {
return "abcdefg";
}
}

class Arm extends Component {
initialize(length) {
this.properties("length");
this.properties("length", "dna");
this.dna("dagca");
this.length(length);
}
}
Expand Down Expand Up @@ -40,6 +45,12 @@ describe("component.link.properties", () => {
.name().should.eql(name);
});

it("should be able to call overridden properties from a parent link", () => {
person.arm()
.dna("aabbagc")
.dna().should.eql("aabbagc");
});

it("should override identical parent properties", () => {
const petName = "Fluffy";
person
Expand Down
7 changes: 6 additions & 1 deletion es6/spec/component/component.properties.then.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ describe(".properties.then(thenFunction)", () => {
it("should call .then each time the property has a value set", () => {
numbers
.value("1")
.value("2")
.value("2");

numbers.value();

numbers
.value("3");

results.should.eql([ "1", "2", "3" ]);
});

Expand Down

0 comments on commit fd68543

Please sign in to comment.