Skip to content

Commit

Permalink
feat(ability): split Ability into PureAbility (base class) and `A…
Browse files Browse the repository at this point in the history
…bility` (preconfigured PureAbility)

This should make migration easier and at the same time open more possibilities to configure `Ability` and improves tree shaking support

Relates to #249 BREAKING CHANGE: `AbilityBuilder.define` was extracted into `defineAbility` function and `AbilityBuilder.extract` was removed

**Before**

```js
import { AbilityBuilder, Ability } from '@casl/ability'

const ability = AbilityBuilder.define((can) => {
  can('read', 'Post')
})

// the same with extract
const { can, rules } = AbilityBuilder.extract()

can('read', 'Post')

const ability = new Ability(rules)
```

**After**

```js
import { defineAbility, Ability, AbilityBuilder } from '@casl/ability'

const ability = defineAbility((can) => {
  can('read', 'Post')
})

// the same with constructor
const { can, rules } = new AbilityBuilder()

can('read', 'Post')

const ability = new Ability(rules)
```
  • Loading branch information
stalniy committed Feb 21, 2020
1 parent 735547e commit 9536205
Show file tree
Hide file tree
Showing 18 changed files with 654 additions and 570 deletions.
38 changes: 30 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"rollup": "^1.1.2",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-node-resolve": "^5.0.0",
"rollup-plugin-uglify": "^6.0.2",
"rollup-plugin-terser": "^5.2.0",
"semantic-release": "15.9.17",
"tslib": "^1.9.3",
"typescript": "~3.7.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/casl-ability/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"access": "public"
},
"scripts": {
"build.core": "rollup -c ../../tools/rollup.config.js -i src/index.ts -g sift:sift -n casl",
"build.core": "rollup -c ../../tools/rollup.config.js -i src/index.ts -g sift:sift,sift/operations:sift.operations -n casl",
"build.extra": "rollup -c ../../tools/rollup.config.js -i src/extra.ts -n casl.extra",
"build.types": "rm -rf ./dist/types/* && tsc",
"build": "npm run build.core && npm run build.extra && npm run build.types",
Expand Down
Loading

0 comments on commit 9536205

Please sign in to comment.