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 4.0 compatibility - drops support for Ember < 3.28 #717

Merged
merged 14 commits into from
Oct 13, 2022
Merged
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
/yarn.lock.ember-try
9 changes: 1 addition & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,9 @@ module.exports = {
browser: true,
},
rules: {
'ember/no-actions-hash': 'off',
'ember/no-classic-classes': 'off',
'ember/no-classic-components': 'off',
'ember/no-computed-properties-in-native-classes': 'off',
'ember/no-get': 'off',
'ember/no-new-mixins': 'off',
'ember/no-volatile-computed-properties': 'off',
'ember/require-tagless-components': 'off',
'ember/use-ember-data-rfc-395-imports': 'off',
'prettier/prettier': ['error', { singleQuote: true }],
},
overrides: [
// node files
Expand All @@ -56,7 +49,7 @@ module.exports = {
extends: ['plugin:node/recommended'],
},
{
// Test files:
// test files
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
rules: {
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,12 @@ jobs:
fail-fast: false
matrix:
try-scenario:
- ember-lts-3.16
- ember-lts-3.20
- ember-lts-3.24
- ember-lts-3.28
- ember-4.0
- ember-release
- ember-beta
- ember-canary
- ember-default-with-jquery
- ember-classic
- embroider-safe
# - embroider-safe
# - embroider-optimized

steps:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@
# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
/yarn.lock.ember-try
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/.eslintignore
/.eslintrc.js
/.git/
/.github/
/.gitignore
/.prettierignore
/.prettierrc.js
Expand All @@ -33,4 +34,7 @@
# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
/yarn.lock.ember-try
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
/coverage/
!.*
.eslintcache
.lint-todo/

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
/yarn.lock.ember-try
15 changes: 1 addition & 14 deletions addon/-private/ember-internals.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
import Ember from 'ember';
import { A } from '@ember/array';

let __EMBER_METAL__;
let emberMetalPaths = [
'@ember/-internals/metal', // ember-source from 3.10
'@ember/-internals/metal/index', // ember-source from 3.13
];
let metalPath = A(emberMetalPaths).find(
(path) => Ember.__loader.registry[path]
);
if (metalPath) {
__EMBER_METAL__ = Ember.__loader.require(metalPath);
}
import __EMBER_METAL__ from '@ember/-internals/metal/index';

export function getDependentKeys(descriptorOrDecorator) {
if (__EMBER_METAL__ && __EMBER_METAL__.descriptorForDecorator) {
Expand Down
2 changes: 1 addition & 1 deletion addon/-private/ember-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { validate as _validate } from 'ember-validators';

export default Base.extend({
validate() {
let result = _validate(this.get('_evType'), ...arguments);
let result = _validate(this._evType, ...arguments);

if (result && typeof result === 'object') {
return result.message
Expand Down
32 changes: 16 additions & 16 deletions addon/-private/internal-result-object.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EmberObject, { computed, set, get } from '@ember/object';
import EmberObject, { computed, set } from '@ember/object';
import { and, not, readOnly } from '@ember/object/computed';
import { isNone } from '@ember/utils';
import { makeArray } from '@ember/array';
Expand All @@ -20,7 +20,7 @@ export default EmberObject.extend({
init() {
this._super(...arguments);

if (this.get('isAsync')) {
if (this.isAsync) {
this._handlePromise();
}
},
Expand All @@ -32,11 +32,11 @@ export default EmberObject.extend({
isTruelyInvalid: and('isNotValidating', 'isInvalid'),

isAsync: computed('_promise', function () {
return isPromise(get(this, '_promise'));
return isPromise(this._promise);
}),

messages: computed('message', function () {
return makeArray(get(this, 'message'));
return makeArray(this.message);
}),

error: computed(
Expand All @@ -46,11 +46,11 @@ export default EmberObject.extend({
'message',
'type',
function () {
if (get(this, 'isInvalid')) {
if (this.isInvalid) {
return ValidationError.create({
type: get(this, '_type'),
message: get(this, 'message'),
attribute: get(this, 'attribute'),
type: this._type,
message: this.message,
attribute: this.attribute,
});
}

Expand All @@ -59,11 +59,11 @@ export default EmberObject.extend({
),

errors: computed('error', function () {
return makeArray(get(this, 'error'));
return makeArray(this.error);
}),

warningMessages: computed('warningMessage', function () {
return makeArray(get(this, 'warningMessage'));
return makeArray(this.warningMessage);
}),

warning: computed(
Expand All @@ -73,11 +73,11 @@ export default EmberObject.extend({
'type',
'warningMessage',
function () {
if (get(this, 'isWarning') && !isNone(get(this, 'warningMessage'))) {
if (this.isWarning && !isNone(this.warningMessage)) {
return ValidationError.create({
type: get(this, '_type'),
message: get(this, 'warningMessage'),
attribute: get(this, 'attribute'),
type: this._type,
message: this.warningMessage,
attribute: this.attribute,
});
}

Expand All @@ -86,13 +86,13 @@ export default EmberObject.extend({
),

warnings: computed('warning', function () {
return makeArray(get(this, 'warning'));
return makeArray(this.warning);
}),

_handlePromise() {
set(this, 'isValidating', true);

get(this, '_promise').finally(() => {
this._promise.finally(() => {
set(this, 'isValidating', false);
});
},
Expand Down
39 changes: 15 additions & 24 deletions addon/-private/result.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { isNone } from '@ember/utils';

import { isArray } from '@ember/array';
import EmberObject, {
getProperties,
setProperties,
computed,
set,
get,
} from '@ember/object';
import EmberObject, { setProperties, computed, set } from '@ember/object';
import { readOnly } from '@ember/object/computed';
import ResultCollection from '../validations/result-collection';
import WarningResultCollection from '../validations/warning-result-collection';
Expand Down Expand Up @@ -62,11 +56,8 @@ const Result = EmberObject.extend({
* @type {Boolean}
*/
_isReadOnly: computed('_result', function () {
let validations = get(this, '_result');
return (
validations instanceof ResultCollection ||
get(validations, 'isValidations')
);
let validations = this._result;
return validations instanceof ResultCollection || validations.isValidations;
}).readOnly(),

/**
Expand Down Expand Up @@ -187,19 +178,19 @@ const Result = EmberObject.extend({
'_validator',
'_resultOverride',
function () {
let { model, attribute, _promise, _validator } = this;

return (
get(this, '_resultOverride') ||
InternalResultObject.create(
getProperties(this, ['model', 'attribute', '_promise', '_validator'])
)
this._resultOverride ||
InternalResultObject.create({ model, attribute, _promise, _validator })
);
}
),

init() {
this._super(...arguments);

if (get(this, 'isAsync') && !get(this, '_isReadOnly')) {
if (this.isAsync && !this._isReadOnly) {
this._handlePromise();
}
},
Expand All @@ -218,22 +209,22 @@ const Result = EmberObject.extend({
* @param value
*/
update(value) {
let result = get(this, '_result');
let attribute = get(this, 'attribute');
let isWarning = get(this, 'isWarning');
let result = this._result;
let attribute = this.attribute;
let isWarning = this.isWarning;
let Collection = isWarning ? WarningResultCollection : ResultCollection;

if (isNone(value)) {
return this.update(false);
} else if (get(value, 'isValidations')) {
} else if (value.isValidations) {
this._overrideResult(Collection.create({ attribute, content: [value] }));
} else if (isArray(value)) {
this._overrideResult(Collection.create({ attribute, content: value }));
} else if (!get(this, '_isReadOnly')) {
} else if (!this._isReadOnly) {
this._overrideResult(undefined);

if (typeof value === 'string') {
setProperties(get(this, '_result'), {
setProperties(this._result, {
[isWarning ? 'warningMessage' : 'message']: value,
isValid: isWarning ? true : false,
});
Expand Down Expand Up @@ -261,7 +252,7 @@ const Result = EmberObject.extend({
* @private
*/
_handlePromise() {
get(this, '_promise')
this._promise
.then(
(value) => this.update(value),
(value) => this.update(value)
Expand Down
4 changes: 2 additions & 2 deletions addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ import Validator from './validations/validator';
* disabled: Ember.computed.not('model.meta.username.isEnabled'),
* min: Ember.computed.readOnly('model.meta.username.minLength'),
* max: Ember.computed.readOnly('model.meta.username.maxLength'),
* description: Ember.computed(function() {
* description: Ember.computed('model', 'attribute', function() {
* // CPs have access to the `model` and `attribute`
* return this.get('model').generateDescription(this.get('attribute'));
* }).volatile() // Disable caching and force recompute on every get call
* })
* })
* });
* ```
Expand Down
6 changes: 3 additions & 3 deletions addon/utils/meta-data.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Ember from 'ember';
import { meta } from '@ember/-internals/meta';

let id = 0;
const dataKey = symbol('data');
Expand All @@ -8,7 +8,7 @@ function symbol(key) {
}

function getData(obj, s) {
let m = Ember.meta(obj);
let m = meta(obj);
let data = m[dataKey];

if (data) {
Expand All @@ -17,7 +17,7 @@ function getData(obj, s) {
}

function setData(obj, s, value) {
let m = Ember.meta(obj);
let m = meta(obj);
let data = (m[dataKey] = m[dataKey] || {});

data[s] = value;
Expand Down
22 changes: 15 additions & 7 deletions addon/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import ArrayProxy from '@ember/array/proxy';
import ObjectProxy from '@ember/object/proxy';
import { isHTMLSafe } from '@ember/template';
import EmberObject, { get } from '@ember/object';
import EmberObject from '@ember/object';
import { typeOf } from '@ember/utils';
import { A as emberArray, isArray } from '@ember/array';
import require from 'require';

import Ember from 'ember';
import requireModule from 'ember-require-module';
function requireModule(module, exportName = 'default') {
if (require.has(module)) {
return require(module)[exportName];
}
}

const DS = requireModule('ember-data');

const { canInvoke } = Ember;

export { getDependentKeys, isDescriptor } from '../-private/ember-internals';

export function unwrapString(s) {
Expand All @@ -23,13 +25,19 @@ export function unwrapString(s) {
}

export function unwrapProxy(o) {
return isProxy(o) ? unwrapProxy(get(o, 'content')) : o;
return isProxy(o) ? unwrapProxy(o.content) : o;
}

export function isProxy(o) {
return !!(o && (o instanceof ObjectProxy || o instanceof ArrayProxy));
}

function canInvoke(obj, methodName) {
return (
obj !== null && obj !== undefined && typeof obj[methodName] === 'function'
);
}

export function isPromise(p) {
return !!(p && canInvoke(p, 'then'));
}
Expand Down Expand Up @@ -57,7 +65,7 @@ export function isObject(o) {

export function isValidatable(value) {
let v = unwrapProxy(value);
return isDsModel(v) ? !get(v, 'isDeleted') : true;
return isDsModel(v) ? !v.isDeleted : true;
}

export function getValidatableValue(value) {
Expand Down
Loading