Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified example with tests and spec changes. #18

Merged
merged 32 commits into from
Oct 2, 2015

Conversation

ericelliott
Copy link
Contributor

Simplified example implementation with tests.

Includes spec changes discussed in #35.

const composable = {};
const methods = getDescriptorProps('methods', composables);

composable.compose = (...args) => {};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously need to implement this. Just trying to illustrate a more self-documenting way to handle the descriptor property mixing for now...

@koresar
Copy link
Member

koresar commented Aug 22, 2015

I am agree to any changes to the example-implementation as long as it's highly readable by other people.

The intention was to make sure any other person can read the code, easily understand it and (re)implement.

If you consider this example code should serve real production - then let it be.

@ericelliott
Copy link
Contributor Author

I am agree to any changes to the example-implementation as long as it's highly readable by other people.

That's what I'm aiming for. I'll do some more work on it this weekend. =)

};

function compose (...composables) {
const composable = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought composable is a factory function. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, these are just placeholders. Like I said, I haven't implemented the stamp bit yet. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sure. :) Seem like you respond in Gitter faster than on GitHub.

* Instance creation
* Initializers run
* Better initializer tests
* New watch task
* Add eslint
* Cleanup lint

// Set up prototype
Object.assign(proto, descriptor.methods);
Object.setPrototypeOf(obj, proto);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd need to check if the object already have a prototype. It should not be overriden.

if (Object.getPrototypeOf(obj) === Object.prototype)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Doing TDD, meaning that I write the minimum code to make the test I'm working on pass.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid making changes to an object's [[Prototype]]. Instead we can just create a new object.

const proto = {};
let obj = instance || {};

// Set up prototype
Object.assign(proto, descriptor.methods);

if (isEmpty(Object.getPrototypeOf(obj))) {
  obj = Object.create(proto);
}

http://jsperf.com/proto-vs-object-create2/2

Before you say it @koresar, I don't consider this a premature optimization. ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm using Object.create() where it's possible, but if a user passes an instance in to be mutated, we can't just Object.create() a new instance. For example, a user might want to use an array or a function, and Object.create() won't work for those cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I overlooked that scenario.

nest.test(`...with pojo descriptor.${ descriptorName }`, assert => {
const descriptor = {
[ descriptorName ]: {
a: 'a'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will throw a TypeError for staticPropertyDescriptors when Object.defineProperties is used in createStamp.

TypeError: Property description must be an object: a

This also applies to all other test files that test property descriptors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll try to got some of the object-instantiation stuff worked out today, so I'll probably run into this soon. =)

ericelliott and others added 13 commits September 28, 2015 17:56
Since it would be trivial to implement `instance` mutation as a stamp, it makes sense to strip it from the stamp spec to simplify things and eliminate any need for reserved properties.

I believe it's still a very good idea to encourage the use of a single `options` object, so that will remain part of the spec.
@ericelliott ericelliott changed the title WIP: Don't Merge Yet. First crack at simplifying the example implementation. Simplified example with tests and spec changes. Oct 1, 2015
@troutowicz
Copy link
Member

This looks good to me. 👍

@koresar
Copy link
Member

koresar commented Oct 2, 2015

Good quality code. Awesome Eric. :)

Tests are comprehensive. I compared them to stampit tests and find that you have covered everything.

I might doubt about some wrding in the README, but it's only a matter of taste.

koresar added a commit that referenced this pull request Oct 2, 2015
Simplified example with tests and spec changes.
@koresar koresar merged commit 5e4fc0e into master Oct 2, 2015
@koresar koresar deleted the ericelliott-simplify-example branch October 2, 2015 01:37
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants