Skip to content

Commit

Permalink
support ember 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinJoyce committed May 29, 2019
1 parent b3a64cc commit 2935149
Show file tree
Hide file tree
Showing 10 changed files with 715 additions and 261 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
fail_fast: true
allow_failures:
- env: EMBER_TRY_SCENARIO=ember-canary
- env: EMBER_TRY_SCENARIO=ember-beta

include:
# runs linting and tests with current locked deps
Expand All @@ -50,6 +51,7 @@ jobs:
env: EMBER_TRY_SCENARIO=ember-lts-2.16
- env: EMBER_TRY_SCENARIO=ember-lts-2.18
- env: EMBER_TRY_SCENARIO=ember-lts-3.4
- env: EMBER_TRY_SCENARIO=ember-lts-3.8
- env: EMBER_TRY_SCENARIO=ember-release
- env: EMBER_TRY_SCENARIO=ember-beta
- env: EMBER_TRY_SCENARIO=ember-canary
Expand Down
27 changes: 27 additions & 0 deletions addon/-private/ember-internals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Ember from 'ember';

let __EMBER_METAL__;
if (Ember.__loader.registry['@ember/-internals/metal']) {
__EMBER_METAL__ = Ember.__loader.require('@ember/-internals/metal');
}

export function getDependentKeys(descriptorOrDecorator) {
if (__EMBER_METAL__ && __EMBER_METAL__.descriptorForDecorator) {
let descriptor = __EMBER_METAL__.descriptorForDecorator(
descriptorOrDecorator
);
return descriptor._dependentKeys;
} else {
return descriptorOrDecorator._dependentKeys;
}
}

export function isDescriptor(o) {
if (__EMBER_METAL__ && __EMBER_METAL__.isClassicDecorator) {
return __EMBER_METAL__.isClassicDecorator(o);
} else {
return (
o && (typeof o === 'object' || typeof o === 'function') && o.isDescriptor
);
}
}
8 changes: 1 addition & 7 deletions addon/-private/options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import EmberObject, { get } from '@ember/object';
import { isDescriptor } from '../utils/utils';

const { keys } = Object;
const OPTION_KEYS = '__option_keys__';
Expand All @@ -18,11 +17,6 @@ export default class Options {
const optionKeys = keys(options);
const createParams = { [OPTION_KEYS]: optionKeys, model, attribute };

// If any of the options is a CP, we need to create a custom class for it
if (optionKeys.some(key => isDescriptor(options[key]))) {
return OptionsObject.extend(options).create(createParams);
}

return OptionsObject.create(createParams, options);
return OptionsObject.extend(options).create(createParams);
}
}
5 changes: 2 additions & 3 deletions addon/utils/deep-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* the pathing requires it. If the given path is `foo.bar`, it will create a new object (obj.foo)
* and assign value to obj.foo.bar. If the given object is an Ember.Object, it will create new Ember.Objects.
*/
import ComputedProperty from '@ember/object/computed';

import { isDescriptor } from './utils';
import { isNone } from '@ember/utils';
import EmberObject, { defineProperty, set, get } from '@ember/object';

Expand All @@ -30,7 +29,7 @@ export default function deepSet(
currObj = get(currObj, key);
}

if (value instanceof ComputedProperty) {
if (isDescriptor(value)) {
defineProperty(currObj, keyPath[lastKeyIndex], value);
} else {
set(currObj, keyPath[lastKeyIndex], value);
Expand Down
6 changes: 2 additions & 4 deletions addon/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const DS = requireModule('ember-data');

const { canInvoke } = Ember;

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

export function unwrapString(s) {
if (isHTMLSafe(s)) {
return s.toString();
Expand Down Expand Up @@ -54,10 +56,6 @@ export function isObject(o) {
return typeOf(o) === 'object' || typeOf(o) === 'instance';
}

export function isDescriptor(o) {
return o && typeof o === 'object' && o.isDescriptor;
}

export function isValidatable(value) {
let v = unwrapProxy(value);
return isDsModel(v) ? !get(v, 'isDeleted') : true;
Expand Down
5 changes: 3 additions & 2 deletions addon/validations/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import shouldCallSuper from '../utils/should-call-super';
import lookupValidator from '../utils/lookup-validator';
import { flatten } from '../utils/array';
import {
getDependentKeys,
isDescriptor,
isDsModel,
isValidatable,
isPromise,
isDescriptor,
mergeOptions
} from '../utils/utils';
import {
Expand Down Expand Up @@ -653,7 +654,7 @@ function extractOptionsDependentKeys(options) {
let option = options[key];

if (isDescriptor(option)) {
return arr.concat(option._dependentKeys || []);
return arr.concat(getDependentKeys(option) || []);
}

return arr;
Expand Down
8 changes: 8 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ module.exports = function() {
}
}
},
{
name: 'ember-lts-3.8',
npm: {
devDependencies: {
'ember-source': '~3.8.0'
}
}
},
{
name: 'ember-release',
npm: {
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
}
],
"devDependencies": {
"@ember-decorators/babel-transforms": "^4.0.0",
"@ember-decorators/data": "^4.0.0",
"@ember/optional-features": "^0.6.3",
"babel-eslint": "^8.2.6",
"bootstrap-sass": "^3.3.7",
Expand All @@ -53,8 +51,7 @@
"ember-cli-uglify": "^2.1.0",
"ember-cli-yuidoc": "^0.8.8",
"ember-code-snippet": "^2.3.1",
"ember-data": "~3.6.0",
"ember-decorators": "^4.0.0",
"ember-data": "~3.8.0",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-export-application-global": "^2.0.0",
"ember-font-awesome": "^3.0.5",
Expand All @@ -64,7 +61,7 @@
"ember-qunit": "^3.4.1",
"ember-qunit-nice-errors": "^1.2.0",
"ember-resolver": "^5.0.1",
"ember-source": "~3.6.0",
"ember-source": "~3.8.0",
"ember-source-channel-url": "^1.1.0",
"ember-test-selectors": "^0.3.8",
"ember-truth-helpers": "2.0.0",
Expand Down
35 changes: 24 additions & 11 deletions tests/dummy/app/models/company.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import Model from 'ember-data/model';
import { attr } from '@ember-decorators/data';
import {
hasValidations,
validator,
buildValidations
} from 'ember-cp-validations';
// TODO: make this pass

// import Model from 'ember-data/model';
// import attr from 'ember-data/attr';
// import {
// hasValidations,
// validator,
// buildValidations
// } from 'ember-cp-validations';

// export const Validations = buildValidations({
// name: validator('presence', { presence: true, description: 'Name' })
// });

// @hasValidations(Validations)
// export default class Company extends Model {
// @attr('string') name;
// }

import DS from 'ember-data';
import { validator, buildValidations } from 'ember-cp-validations';

export const Validations = buildValidations({
name: validator('presence', { presence: true, description: 'Name' })
});

@hasValidations(Validations)
export default class Company extends Model {
@attr('string') name;
}
export default DS.Model.extend(Validations, {
name: DS.attr('string')
});
Loading

0 comments on commit 2935149

Please sign in to comment.