CASL v5.1.0-next.11 Release Notes
Release Date: 2020-10-17 // over 3 years ago-
5.1.0-next.11 (2020-10-17)
๐ Bug Fixes
- README: removes explanation duplicated from intro guide (6315aa7)
๐จ Code Refactoring
- ruleIndex:
detectSubjectType
option is now responsible only for detecting subject type from objects [skip release] (ebeaadc)
๐ฅ BREAKING CHANGES
ruleIndex: string and class (or function constructor) are the only possible subject types for now.
detectSubjectType
is now responsible only for detecting subject type from objectBefore
When providing subject type it was important to handle cases when passed in argument is a string or function. As an alternative it was possible to call built-in
detectSubjectType
which could catch this cases:import { Ability } from '@casl/ability';const ability = new Ability([], {detectSubjectType(object) {if (object && typeof object === 'object') {return object.\_\_typename;}return detectSubjectType(object);});
After
There is no need to handle subject type values in
detectSubjectType
function anymore. It's now handled internally:import { Ability } from '@casl/ability';const ability = new Ability([], {detectSubjectType: object =\> object.\_\_typename});
Also it's important to note that if you want it's no longer possible to use classes and strings as subject types interchangably together as it was before. Now, if you want to use classes, you should use them everywhere:
Before
import { defineAbility } from '@casl/ability';class Post {}const ability = defineAbility((can) =\> {can('read', Post);can('update', 'Post');});ability.can('read', 'Post') // trueability.can('read', Post) // trueability.can('update', Post) // true
After
import { defineAbility } from '@casl/ability';class Post {}const ability = defineAbility((can) =\> {can('read', Post);can('update', 'Post');});ability.can('read', 'Post') // false, 'Post' and Post are considered different nowability.can('read', Post) // trueability.can('update', Post) // false