diff --git a/.travis.yml b/.travis.yml index 7b4547c6..8dc197ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,6 @@ branches: jobs: fast_finish: true allow_failures: - - env: EMBER_TRY_SCENARIO=ember-release - env: EMBER_TRY_SCENARIO=ember-beta - env: EMBER_TRY_SCENARIO=ember-canary diff --git a/README.md b/README.md index 84dfc678..47eac8b5 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,7 @@ export default class Foo extends Component { constructor(owner, args) { super(owner, args); - this.changeset = new Changeset(args.user); + this.changeset = Changeset(args.user); } } ``` diff --git a/addon/helpers/changeset.js b/addon/helpers/changeset.js index 0c9a8eac..64761a8e 100644 --- a/addon/helpers/changeset.js +++ b/addon/helpers/changeset.js @@ -1,5 +1,5 @@ import { helper } from '@ember/component/helper'; -import Changeset from 'ember-changeset'; +import { Changeset } from 'ember-changeset'; import { lookupValidator, isChangeset, isPromise, isObject } from 'validated-changeset'; export function changeset( @@ -13,18 +13,18 @@ export function changeset( if (isObject(validations)) { if (isPromise(obj)) { return obj.then((resolved) => - new Changeset(resolved, lookupValidator(validations), validations, options) + Changeset(resolved, lookupValidator(validations), validations, options) ); } - return new Changeset(obj, lookupValidator(validations), validations, options); + return Changeset(obj, lookupValidator(validations), validations, options); } if (isPromise(obj)) { - return Promise.resolve(obj).then((resolved) => new Changeset(resolved, validations, {}, options)); + return Promise.resolve(obj).then((resolved) => Changeset(resolved, validations, {}, options)); } - return new Changeset(obj, validations, {}, options); + return Changeset(obj, validations, {}, options); } export default helper(changeset); diff --git a/addon/index.js b/addon/index.js index 4d3d67df..d0d60c67 100644 --- a/addon/index.js +++ b/addon/index.js @@ -187,7 +187,7 @@ export class EmberChangeset extends BufferedChangeset { // return getters/setters/methods on BufferedProxy instance - if (this[key]) { + if (typeof this[key] !== 'undefined') { return this[key]; } else if (this[baseKey]) { const v = this[baseKey]; diff --git a/config/ember-try.js b/config/ember-try.js index 464a5a6f..6a91d70f 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -24,7 +24,6 @@ module.exports = async function() { }, { name: 'ember-release', - allowedToFail: true, npm: { devDependencies: { 'ember-source': await getChannelURL('release') diff --git a/tests/dummy/app/components/changeset-form.js b/tests/dummy/app/components/changeset-form.js index efa5783c..88408cca 100644 --- a/tests/dummy/app/components/changeset-form.js +++ b/tests/dummy/app/components/changeset-form.js @@ -17,7 +17,11 @@ export default class ChangesetForm extends Component { } } - changeset = Changeset(this.model) + init() { + super.init(...arguments); + + this.changeset = Changeset(this.model) + } @action submitForm(changeset, event) { diff --git a/tests/integration/components/changeset-test.js b/tests/integration/components/changeset-test.js index 5c24836d..0750e0da 100644 --- a/tests/integration/components/changeset-test.js +++ b/tests/integration/components/changeset-test.js @@ -1,7 +1,7 @@ import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; import { typeOf, isPresent } from '@ember/utils'; -import Changeset from 'ember-changeset'; +import { Changeset } from 'ember-changeset'; import hbs from 'htmlbars-inline-precompile'; import { render, @@ -228,7 +228,7 @@ module('Integration | Helper | changeset', function(hooks) { this.set('dummyModel', { firstName: 'Jim', lastName: 'Bob' }); this.set('validate', () => true); await render(hbs` - {{#with (changeset dummyModel (action validate)) as |changesetObj|}} + {{#with (changeset this.dummyModel (action this.validate)) as |changesetObj|}}

{{changesetObj.firstName}} {{changesetObj.lastName}}

{{changeset.person.firstName}} {{changeset.person.lastName}} +

{{this.changeset.person.firstName}} {{this.changeset.person.lastName}}

+ value={{this.changeset.person.firstName}} + onchange={{action (changeset-set this.changeset "person.firstName") value="target.value"}}> > + value={{this.changeset.person.lastName}} + onchange={{action (changeset-set this.changeset "person.lastName") value="target.value"}}> `); assert.equal(find('h1').textContent.trim(), 'Jim Bob', 'precondition'); @@ -277,18 +277,18 @@ module('Integration | Helper | changeset', function(hooks) { test('nested object updates when set without a validator', async function(assert) { let data = { person: { firstName: 'Jim', lastName: 'Bob' } }; - let changeset = new Changeset(data); + let changeset = Changeset(data); this.set('changeset', changeset); await render(hbs` -

{{changeset.person.firstName}} {{changeset.person.lastName}}

+

{{this.changeset.person.firstName}} {{this.changeset.person.lastName}}

+ value={{this.changeset.person.firstName}} + onchange={{action (changeset-set this.changeset "person.firstName") value="target.value"}}> + value={{this.changeset.person.lastName}} + onchange={{action (changeset-set this.changeset "person.lastName") value="target.value"}}> `); assert.equal(find('h1').textContent.trim(), 'Jim Bob', 'precondition'); @@ -300,7 +300,7 @@ module('Integration | Helper | changeset', function(hooks) { test('nested key error clears after entering valid input', async function(assert) { let data = { person: { firstName: 'Jim' } }; let validator = ({ newValue }) => isPresent(newValue) || 'need a first name'; - let c = new Changeset(data, validator); + let c = Changeset(data, validator); this.set('c', c); await render(hbs` @@ -331,7 +331,7 @@ module('Integration | Helper | changeset', function(hooks) { test('nested object updates when set with async validator', async function(assert) { let data = { person: { firstName: 'Jim' } }; let validator = () => Promise.resolve(true); - let c = new Changeset(data, validator); + let c = Changeset(data, validator); this.set('c', c); await render(hbs`

{{c.person.firstName}}

@@ -350,7 +350,7 @@ module('Integration | Helper | changeset', function(hooks) { test('deeply nested key error clears after entering valid input', async function(assert) { let data = { person: { name: { parts: { first: 'Jim' } } } }; let validator = ({ newValue }) => isPresent(newValue) || 'need a first name'; - let c = new Changeset(data, validator); + let c = Changeset(data, validator); this.set('c', c); await render(hbs` @@ -383,20 +383,20 @@ module('Integration | Helper | changeset', function(hooks) { test('a rollback propagates binding to deeply nested changesets', async function(assert) { let data = { person: { firstName: 'Jim', lastName: 'Bob' } }; - let changeset = new Changeset(data); + let changeset = Changeset(data); this.set('changeset', changeset); this.set('reset', () => changeset.rollback()); await render(hbs` -

{{changeset.person.firstName}} {{changeset.person.lastName}}

+

{{this.changeset.person.firstName}} {{this.changeset.person.lastName}}

+ value={{this.changeset.person.firstName}} + onchange={{action (changeset-set this.changeset "person.firstName") value="target.value"}}> - + value={{this.changeset.person.lastName}} + onchange={{action (changeset-set this.changeset "person.lastName") value="target.value"}}> + `); assert.equal(find('h1').textContent.trim(), 'Jim Bob', 'precondition'); @@ -415,7 +415,7 @@ module('Integration | Helper | changeset', function(hooks) { let lookupValidator = (validationMap) => { return ({ key, newValue }) => [validationMap[key](newValue)]; }; - let changeset = new Changeset({ even: 4, odd: 4 }, lookupValidator(dummyValidations), dummyValidations); + let changeset = Changeset({ even: 4, odd: 4 }, lookupValidator(dummyValidations), dummyValidations); this.set('changeset', changeset); this.set('validateProperty', (changeset, property) => changeset.validate(property)); await render(hbs` @@ -424,13 +424,13 @@ module('Integration | Helper | changeset', function(hooks) { - {{#if changeset.error.even}} - {{changeset.error.even.validation}} + value={{this.changeset.even}} + oninput={{action (mut this.changeset.even) value="target.value"}} + onblur={{action this.validateProperty this.changeset "even"}}> + {{#if this.changeset.error.even}} + {{this.changeset.error.even.validation}} {{/if}} - {{changeset.even}} + {{this.changeset.even}}
@@ -438,13 +438,13 @@ module('Integration | Helper | changeset', function(hooks) { - {{#if changeset.error.odd}} - {{changeset.error.odd.validation}} + value={{this.changeset.odd}} + oninput={{action (mut this.changeset.odd) value="target.value"}} + onblur={{action this.validateProperty this.changeset "odd"}}> + {{#if this.changeset.error.odd}} + {{this.changeset.error.odd.validation}} {{/if}} - {{changeset.odd}} + {{this.changeset.odd}}
`); @@ -476,7 +476,7 @@ module('Integration | Helper | changeset', function(hooks) { let momentInstance = new Moment(d); this.set('dummyModel', { startDate: momentInstance }); await render(hbs` - {{#with (changeset dummyModel) as |changesetObj|}} + {{#with (changeset this.dummyModel) as |changesetObj|}}

{{changesetObj.startDate.date}}

{{/with}} `); @@ -488,7 +488,7 @@ module('Integration | Helper | changeset', function(hooks) { let d = new Date('2015'); this.set('d', d); await render(hbs` - {{#with (changeset (hash date=d)) as |changesetObj|}} + {{#with (changeset (hash date=this.d)) as |changesetObj|}}

{{changesetObj.date}}

{{/with}} `); @@ -499,7 +499,7 @@ module('Integration | Helper | changeset', function(hooks) { test('it handles models that are promises', async function(assert) { this.set('dummyModel', Promise.resolve({ firstName: 'Jim', lastName: 'Bob' })); await render(hbs` - {{#with (changeset dummyModel) as |changesetObj|}} + {{#with (changeset this.dummyModel) as |changesetObj|}}

{{changesetObj.firstName}} {{changesetObj.lastName}}

false); await render(hbs` - {{#with (changeset dummyModel (action validate) skipValidate=true) as |changesetObj|}} + {{#with (changeset this.dummyModel (action this.validate) skipValidate=true) as |changesetObj|}}

{{changesetObj.firstName}} {{changesetObj.lastName}}

{{input id="first-name" value=changesetObj.firstName}} {{input id="last-name" value=changesetObj.lastName}} diff --git a/tests/integration/helpers/changeset-get-test.ts b/tests/integration/helpers/changeset-get-test.ts index 881d56b7..5e2dd5bc 100644 --- a/tests/integration/helpers/changeset-get-test.ts +++ b/tests/integration/helpers/changeset-get-test.ts @@ -3,7 +3,7 @@ import { setupRenderingTest } from 'ember-qunit'; import { TestContext } from 'ember-test-helpers'; import hbs from 'htmlbars-inline-precompile'; import { module, test } from 'qunit'; -import Changeset from 'ember-changeset'; +import { Changeset } from 'ember-changeset'; interface ModelType { name: { first: string; last: string }; @@ -26,7 +26,7 @@ module('Integration | Helper | changeset-get', function(hooks) { url: 'http://bobloblawslawblog.com' }; - this.set('changeset', new Changeset(model)); + this.set('changeset', Changeset(model)); this.set('fieldName', 'name.first'); });