Skip to content

Commit

Permalink
[FEATURE] Adds support for parenless data decorators
Browse files Browse the repository at this point in the history
Adds support for `@attr`, `@belongsTo`, `@hasMany` without parens
  • Loading branch information
Chris Garrett committed Oct 24, 2019
1 parent 78dcb03 commit 484fc51
Show file tree
Hide file tree
Showing 9 changed files with 640 additions and 525 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ module.exports = {
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module'
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true
}
},
plugins: [
'ember'
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: node_js
node_js:
# we recommend testing addons with the same minimum supported node version as Ember CLI
# so that your addon works for all apps
- '6'
- '8'

sudo: false
dist: trusty
Expand Down
9 changes: 9 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ module.exports = function() {
}
}
},
{
name: 'ember-lts-3.12',
npm: {
devDependencies: {
'ember-data': '~3.12.0',
'ember-source': '~3.12.0'
}
}
},
{
name: 'ember-release',
npm: {
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ module.exports = {

let checker = new VersionChecker(this.project);
let emberVersion = checker.forEmber();
let emberDataVersion = checker.for('ember-data');

this.shouldPolyfill = emberVersion.lt('3.10.0-alpha.1');
this.shouldPolyfill = emberVersion.lt('3.10.0-alpha.0') || emberDataVersion.lt('3.10.0-alpha.0');
},

included() {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"ember-cli-sri": "^2.1.1",
"ember-cli-template-lint": "^1.0.0-beta.1",
"ember-cli-uglify": "^2.1.0",
"ember-data": "^3.9.0",
"ember-data": "~3.9.0",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-export-application-global": "^2.0.0",
"ember-load-initializers": "^1.1.0",
Expand All @@ -54,7 +54,7 @@
"qunit-dom": "^0.8.0"
},
"engines": {
"node": "6.* || 8.* || >= 10.*"
"node": "8.* || >= 10.*"
},
"ember-addon": {
"configPath": "tests/dummy/config",
Expand Down
1 change: 1 addition & 0 deletions tests/unit/action-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { setupRenderingTest, skip } from 'ember-qunit';
import { render, click, findAll } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';


function registerComponent(
test,
name,
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/data-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,44 @@ module('ember-data', function(hooks) {

assert.equal(names, expectedNames, 'The correct records are in the array');
});

test('@attr can be used without parens', async function(assert) {
let Post = class extends DS.Model {
@DS.attr name;
};

register(`model:post`, Post);
stubAdapter();

let store = getService('store');
let posts = await store.peekAll('post');
let names = posts
.toArray()
.map(post => get(post, 'name'))
.join();

assert.equal(names, expectedNames, 'The correct records are in the array');
});

if (gte('ember-data', '3.11.0')) {
test('@attr works with module imports without parens', async function(assert) {
let { default: Model, attr } = window.require('@ember-data/model');

let Post = class extends Model {
@attr name;
};

register(`model:post`, Post);
stubAdapter();

let store = getService('store');
let posts = await store.peekAll('post');
let names = posts
.toArray()
.map(post => get(post, 'name'))
.join();

assert.equal(names, expectedNames, 'The correct records are in the array');
});
}
});
Loading

0 comments on commit 484fc51

Please sign in to comment.