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 b453ad5
Show file tree
Hide file tree
Showing 7 changed files with 839 additions and 656 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
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
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 b453ad5

Please sign in to comment.