Skip to content

Commit

Permalink
refactor(example): replaces AppVue with Vue module augmentation
Browse files Browse the repository at this point in the history
This is possible due to changes in @casl/[email protected]

Relates to stalniy/casl#312
  • Loading branch information
stalniy committed May 12, 2020
1 parent 192eeba commit 898c515
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/vue-todo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"@casl/ability": "^4.0.5",
"@casl/vue": "^1.0.3",
"@casl/vue": "^1.1.0",
"core-js": "^3.6.4",
"vue": "^2.6.11"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-todo/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</template>

<script lang="ts">
import Vue from './AppVue';
import Vue from 'vue';
import TodoList from './components/TodoList.vue';
export default Vue.extend({
Expand Down
8 changes: 0 additions & 8 deletions packages/vue-todo/src/AppVue.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/vue-todo/src/components/NewTodo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</template>

<script lang="ts">
import Vue from '../AppVue';
import Vue from 'vue';
export default Vue.extend({
name: 'NewTodo',
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-todo/src/components/TodoFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</template>

<script lang="ts">
import Vue from '../AppVue';
import Vue from 'vue';
import { defineRulesFor } from '../config/ability';
import { Todo } from '../models/Todo';
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-todo/src/components/TodoItems.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</template>

<script lang="ts">
import Vue from '../AppVue';
import Vue from 'vue';
import { Todo, TodoInput } from '../models/Todo';
type State = {
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-todo/src/components/TodoList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</template>

<script lang="ts">
import Vue from '../AppVue';
import Vue from 'vue';
import TodoItems, { UpdateEvent } from './TodoItems.vue';
import TodoFooter from './TodoFooter.vue';
import NewTodo from './NewTodo.vue';
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-todo/src/config/ability.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PureAbility, AbilityBuilder, Ability, detectSubjectType, AbilityClass, InferSubjects } from '@casl/ability';
import { AbilityBuilder, Ability, detectSubjectType, AbilityClass, InferSubjects } from '@casl/ability';
import { Todo } from '../models/Todo'

type Actions = 'manage' | 'create' | 'read' | 'update' | 'delete';
Expand All @@ -14,7 +14,7 @@ export function defineRulesFor(role: string) {
can('manage', 'all');
} else {
can('read', 'all');
can(['update', 'delete'], 'Todo', { assignee: 'me' });
can(['create', 'update', 'delete'], 'Todo', { assignee: 'me' });
}

return rules;
Expand Down
13 changes: 13 additions & 0 deletions packages/vue-todo/src/shims-ability.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { AppAbility } from './config/ability'

declare module 'vue/types/vue' {
interface Vue {
$ability: AppAbility;
$can(this: this, ...args: Parameters<this['$ability']['can']>): boolean;
}
}
declare module 'vue/types/options' {
interface ComponentOptions<V extends Vue> {
ability?: AppAbility;
}
}
3 changes: 3 additions & 0 deletions packages/vue-todo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"paths": {
"@/*": [
"src/*"
],
"@casl/vue/patch": [
"src/shims-ability.d.ts"
]
},
"lib": [
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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

0 comments on commit 898c515

Please sign in to comment.