minutebase / ember-can

Simple authorisation addon for Ember apps
http://ember-can.com
MIT License
271 stars 50 forks source link

Use native ES6 classes instead of EmberObject for Ability #138

Open Gorzas opened 3 years ago

Gorzas commented 3 years ago

The latests versions of EmberJS are deprecating the use of EmberObject and Ember computed properties to use native ones instead. This could be a good improvement, also if we think in making it easier for users of other frameworks to start using EmberJS. An start could be changing the Ability class to use ES6 native classes.

I think this changes should be for a potential new major version (4.0.0 of ember-can) as it could remove some compatibilities with older versions of EmberJS. What do you think?

tben commented 3 years ago

Btw, you can just use the ability class just like before.

import { Ability } from 'ember-can';

export default class AuthUser extends Ability {
    get canUserManage() {
        return true;
    }
}
Gorzas commented 3 years ago

I've migrated Ability to ES6 class but it still needs more work to be done. Right now, it still depends on EmberObject:

import EmberObject, { get }  from '@ember/object';
import { camelize } from '@ember/string';

export default class Ability extends EmberObject {
  model = null;

This may be because this line but I decided it's a problem worth to be solved later.

And it's also being tested using computed properties instead of the new tracked syntax.

Gorzas commented 3 years ago

Just as reminder there are two changes left to finish this issue as talked about in the PR: