-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react): adds generics for Ability and related components [skip ci]
Prefixed private methods with _ Relates to #256 BREAKING CHANGES
- Loading branch information
Showing
6 changed files
with
68 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1 @@ | ||
import { PureComponent, StatelessComponent } from 'react' | ||
import { Ability } from '@casl/ability' | ||
|
||
type BaseProps = { | ||
do: string | ||
on: any | ||
} | { | ||
I: string | ||
a: string | ||
} | { | ||
I: string | ||
an: string | ||
} | { | ||
I: string | ||
of: any | ||
} | { | ||
I: string | ||
this: any | ||
}; | ||
|
||
type CanPropsStrict = BaseProps & { | ||
ability: Ability | ||
not?: boolean | ||
passThrough?: boolean | ||
} | ||
|
||
type CanProps = BaseProps & { | ||
ability?: Ability | ||
not?: boolean | ||
passThrough?: boolean | ||
} | ||
|
||
declare class CanComponent<T> extends PureComponent<T> { | ||
allowed: boolean | ||
} | ||
|
||
export class Can extends CanComponent<CanPropsStrict> { | ||
} | ||
|
||
export class BoundCan extends CanComponent<CanProps> { | ||
} | ||
|
||
export function createCanBoundTo(ability: Ability): typeof BoundCan | ||
|
||
export function createContextualCan(Consumer: any): StatelessComponent<CanProps> | ||
export * from './dist/types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { default as Can } from './Can'; | ||
export * from './Can'; | ||
export * from './factory'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters