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

Expose changeset content #287

Merged
merged 1 commit into from
Feb 22, 2018

Conversation

makepanic
Copy link
Contributor

Changes proposed in this pull request

This PR adds a new readonly getter that returns the object that was wrapped in the changeset.
The change can potentially close #139 as it exposes a way to access _content.

I'm unsure if content is a good name as it potentially conflicts with the proxied objects content attribute.

@makepanic
Copy link
Contributor Author

We could also rename it to data to mimic the way ecto exposes the source data.

@nucleartide
Copy link
Contributor

Awesome, thanks for taking the time @makepanic. I'll review this after work today.

Copy link
Contributor

@nucleartide nucleartide left a comment

Choose a reason for hiding this comment

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

Looks good! Just some minor comments.

README.md Outdated

```js
let user = { name: 'Bobby', age: 21, address: { zipCode: '10001' } };

Copy link
Contributor

Choose a reason for hiding this comment

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

Add let changeset = new Changeset(user);?

addon/index.js Outdated
@@ -177,6 +181,7 @@ export function changeset(
errors: objectToArray(ERRORS, (e /*: Err */) => ({ value: e.value, validation: e.validation }), true),
change: inflate(CHANGES, c => c.value),
error: inflate(ERRORS, e => ({ value: e.value, validation: e.validation })),
content: reads(CONTENT).readOnly(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be readOnly(CONTENT), without the reads?


assert.throws(() => set(dummyChangeset, 'content', { foo: 'bar' }), ({message}) => {
return message === "Cannot set read-only property 'content' on object: changeset:[object Object]";
}, 'should throw error');
Copy link
Contributor

Choose a reason for hiding this comment

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

assert.throws(
  () => set(dummyChangeset, 'content', { foo: 'bar' }),
  ({ message }) => message === "Cannot set read-only property 'content' on object: changeset:[object Object]",
  'should throw error'
);

Would like to see the args on separate lines just for clarity. :)

@makepanic
Copy link
Contributor Author

I've made the requested changes and renamed the attribute to data as mentioned in slack.

@nucleartide nucleartide merged commit 9b305d9 into adopted-ember-addons:master Feb 22, 2018
@nucleartide
Copy link
Contributor

@makepanic Wrote up some release notes and published the latest on npm, thanks for the PR dude! Lemme know if there are any problems.

@axsuul
Copy link

axsuul commented Mar 20, 2018

I don't believe this data accessor works for Ember models due to the readOnly wrapper.

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.

Return _content after execute instead of this
4 participants