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

Ember Form For - Changes Required for Ember upgrade 3.28 #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions addon/components/fields-for.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import Ember from 'ember';
import layout from '../templates/components/fields-for';

const {
Component,
set
} = Ember;
import Component from '@ember/component';
import { set } from '@ember/object';

const FieldsForComponent = Component.extend({
layout,
Expand Down
6 changes: 3 additions & 3 deletions addon/components/form-controls/button.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Ember from 'ember';
import DynamicAttributeBindings from 'ember-one-way-controls/-private/dynamic-attribute-bindings';
import layout from '../../templates/components/form-controls/button';

const { Component, get, set, inject: { service } } = Ember;
import Component from '@ember/component';
import { get, set } from '@ember/object';
import { inject as service } from '@ember/service';

const Button = Component.extend(DynamicAttributeBindings, {
layout,
Expand Down
17 changes: 10 additions & 7 deletions addon/components/form-controls/submit.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import Ember from 'ember';
import EmberObject from '@ember/object';
import Button from './button';
import layout from 'ember-form-for/templates/components/form-controls/submit';

const { computed: { alias }, PromiseProxyMixin, RSVP, computed, observer } = Ember;
import { computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import { resolve } from 'rsvp';
import { observer } from '@ember/object';
import ObjectProxy from '@ember/object/proxy';
import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';

const SubmitButton = Button.extend({
layout,
Expand Down Expand Up @@ -31,10 +34,10 @@ const SubmitButton = Button.extend({
// PromiseProxyMixin allows us to use .isPending in the templates
// RSVP.Promise is required to handle situation when submit function
// returns non-promise.
this.set('activePromise', EmberObject.extend(PromiseProxyMixin).create({
promise: new RSVP.Promise((resolve) => {
resolve(this.get('submit')());
})
// Updated as per ember docs https://api.emberjs.com/ember/3.28/classes/PromiseProxyMixin
let ObjectPromiseProxy = ObjectProxy.extend(PromiseProxyMixin);
this.set('activePromise', ObjectPromiseProxy.create({
promise: resolve(this.get('submit')())
}));
return false;
},
Expand Down
9 changes: 2 additions & 7 deletions addon/components/form-errors.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import Ember from 'ember';
import layout from '../templates/components/form-errors';

const {
Component,
computed,
get
} = Ember;
import Component from '@ember/component';
import { computed, get } from '@ember/object';

export default Component.extend({
layout,
Expand Down
30 changes: 14 additions & 16 deletions addon/components/form-field.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import Ember from 'ember';
import layout from '../templates/components/form-field';

import Component from '@ember/component';
import { assert } from '@ember/debug';
import { computed, get, set } from '@ember/object';
import { notEmpty, or, reads } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import { isEmpty, isPresent } from '@ember/utils';
import { dasherize } from '@ember/string';
import { humanize } from '../utils/strings';
import { guidFor } from '@ember/object/internals';
import { observer } from '@ember/object';

const {
Component,
String: { dasherize },
assert,
computed,
computed: { notEmpty, or, reads },
get,
getWithDefault,
guidFor,
inject: { service },
isEmpty,
isPresent,
mixin,
observer,
set
mixin
} = Ember;

const FormFieldComponent = Component.extend({
Expand Down Expand Up @@ -164,14 +160,16 @@ const FormFieldComponent = Component.extend({
},

value: computed('rawValue', function() {
let serializeValue = getWithDefault(this, 'serializeValue', (value) => value);
let serializeValue = get(this, 'serializeValue');
serializeValue = serializeValue !== undefined ? serializeValue : (value) => value;
return serializeValue(get(this, 'rawValue'));
}),

actions: {
processUpdate(object, propertyName, value) {
let rawValue = get(this, 'rawValue');
let deserializeValue = getWithDefault(this, 'deserializeValue', (value) => value);
let deserializeValue = get(this, 'deserializeValue');
deserializeValue = deserializeValue !== undefined ? deserializeValue : (value) => value;
get(this, 'update')(object, propertyName, deserializeValue(value, rawValue));
}
}
Expand Down
7 changes: 2 additions & 5 deletions addon/components/form-fields/checkbox-field.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import Ember from 'ember';
import layout from '../../templates/components/form-fields/checkbox-field';
import Component from '@ember/component';
import { set } from '@ember/object';

const {
Component,
set
} = Ember;

const CheckboxFieldComponent = Component.extend({
tagName: '',
Expand Down
7 changes: 2 additions & 5 deletions addon/components/form-fields/checkbox-group.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import Ember from 'ember';
import layout from '../../templates/components/form-fields/checkbox-group';

const {
Component,
get
} = Ember;
import Component from '@ember/component';
import { get } from '@ember/object';

const CheckboxGroupComponent = Component.extend({
tagName: '',
Expand Down
16 changes: 6 additions & 10 deletions addon/components/form-fields/checkbox-group/option.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import Ember from 'ember';
import layout from '../../../templates/components/form-fields/checkbox-group/option';

import { humanize } from '../../../utils/strings';

const {
Component,
String: { dasherize },
computed,
computed: { or },
get,
inject: { service },
isPresent
} = Ember;
import Component from '@ember/component';
import { computed, get } from '@ember/object';
import { or } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import { isPresent } from '@ember/utils';
import { dasherize } from '@ember/string';

export default Component.extend({
tagName: '',
Expand Down
8 changes: 2 additions & 6 deletions addon/components/form-fields/custom-field.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import Ember from 'ember';
import layout from '../../templates/components/form-fields/custom-field';

const {
Component,
set
} = Ember;
import Component from '@ember/component';
import { set } from '@ember/object';

const CustomFieldComponent = Component.extend({
tagName: '',
Expand Down
4 changes: 1 addition & 3 deletions addon/components/form-fields/date-field.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Ember from 'ember';
import TextField from './text-field';
import { toDateString } from '../../utils/date';

const { isEmpty } = Ember;
import { isEmpty } from '@ember/utils';

export default TextField.extend({
type: 'date',
Expand Down
7 changes: 2 additions & 5 deletions addon/components/form-fields/hidden-field.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import Ember from 'ember';
import layout from '../../templates/components/form-fields/hidden-field';

const {
Component,
set
} = Ember;
import Component from '@ember/component';
import { set } from '@ember/object';

const HiddenFieldComponent = Component.extend({
tagName: '',
Expand Down
17 changes: 6 additions & 11 deletions addon/components/form-fields/radio-field.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import Ember from 'ember';
import layout from '../../templates/components/form-fields/radio-field';

import { humanize } from '../../utils/strings';

const {
Component,
String: { dasherize },
computed,
computed: { or },
get,
inject: { service },
isPresent,
set
} = Ember;
import Component from '@ember/component';
import { computed, get, set } from '@ember/object';
import { or } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import { isPresent } from '@ember/utils';
import { dasherize } from '@ember/string';

const RadioFieldComponent = Component.extend({
tagName: '',
Expand Down
8 changes: 2 additions & 6 deletions addon/components/form-fields/radio-group.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import Ember from 'ember';
import layout from '../../templates/components/form-fields/radio-group';

const {
Component,
set
} = Ember;
import Component from '@ember/component';
import { set } from '@ember/object';

const RadioGroupComponent = Component.extend({
tagName: '',
Expand Down
8 changes: 2 additions & 6 deletions addon/components/form-fields/select-field.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import Ember from 'ember';
import layout from '../../templates/components/form-fields/select-field';

const {
Component,
set
} = Ember;
import Component from '@ember/component';
import { set } from '@ember/object';

const SelectFieldComponent = Component.extend({
tagName: '',
Expand Down
4 changes: 2 additions & 2 deletions addon/components/form-fields/text-field.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ember from 'ember';
import layout from '../../templates/components/form-fields/text-field';

const { Component, set, get } = Ember;
import Component from '@ember/component';
import { set, get } from '@ember/object';

const TextFieldComponent = Component.extend({
tagName: '',
Expand Down
7 changes: 2 additions & 5 deletions addon/components/form-fields/textarea-field.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import Ember from 'ember';
import layout from '../../templates/components/form-fields/textarea-field';

const {
Component,
set
} = Ember;
import Component from '@ember/component';
import { set } from '@ember/object';

const TextareaFieldComponent = Component.extend({
tagName: '',
Expand Down
15 changes: 5 additions & 10 deletions addon/components/form-for.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import Ember from 'ember';
import layout from '../templates/components/form-for';

const {
Component,
get,
inject: { service },
isPresent,
run: { schedule },
set
} = Ember;
import Component from '@ember/component';
import { get, set } from '@ember/object';
import { inject as service } from '@ember/service';
import { isPresent } from '@ember/utils';
import { schedule } from '@ember/runloop';

const FormForComponent = Component.extend({
layout,
Expand Down
5 changes: 1 addition & 4 deletions addon/components/form-for/custom-tag.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import Ember from 'ember';
import layout from '../../templates/components/form-for/custom-tag';

const {
Component
} = Ember;
import Component from '@ember/component';

export default Component.extend({
layout,
Expand Down
9 changes: 2 additions & 7 deletions addon/components/form-hint.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import Ember from 'ember';
import Component from '@ember/component';
import { computed, get } from '@ember/object';
import layout from '../templates/components/form-hint';

const {
Component,
computed,
get
} = Ember;

export default Component.extend({
tagName: '',
layout,
Expand Down
6 changes: 1 addition & 5 deletions addon/components/form-label.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import Ember from 'ember';
import layout from '../templates/components/form-label';

const {
Component
} = Ember;
import Component from '@ember/component';

const FormLabelComponent = Component.extend({
tagName: 'label',
Expand Down
9 changes: 2 additions & 7 deletions addon/helpers/contains.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import Ember from 'ember';

const {
A: emberArray,
Helper: { helper },
isArray
} = Ember;
import { A as emberArray, isArray } from '@ember/array';
import { helper } from '@ember/component/helper';

export function contains([haystack, needle]) {
if (isArray(haystack)) {
Expand Down
6 changes: 1 addition & 5 deletions addon/helpers/form-for/humanize.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import Ember from 'ember';
import { humanize } from '../../utils/strings';

const {
Helper: { helper }
} = Ember;
import { helper } from '@ember/component/helper';

export function formForHumanize([string]) {
return humanize(string);
Expand Down
5 changes: 1 addition & 4 deletions addon/helpers/form-for/merge-custom-form-field.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import Ember from 'ember';

const {
Helper: { helper }
} = Ember;
import { helper } from '@ember/component/helper';

export function formForMergeCustomFormField([formFieldsHash], { name, component }) {
formFieldsHash[name] = component;
Expand Down
6 changes: 1 addition & 5 deletions addon/helpers/is-equal.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import Ember from 'ember';
import isEqual from '../utils/is-equal';

const {
Helper: { helper }
} = Ember;
import { helper } from '@ember/component/helper';

export default helper(([a, b]) => isEqual(a, b));
Loading