-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: vue 2 support for provideLocal and injectLocal
- Loading branch information
1 parent
87ea324
commit 9bfc23c
Showing
4 changed files
with
52 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { type InjectionKey, defineComponent, h } from 'vue-demi' | ||
import { injectLocal, provideLocal } from '@vueuse/shared' | ||
import { describe, expect, it } from 'vitest' | ||
import { mount } from '../../.test' | ||
|
||
{ | ||
const CountKey: InjectionKey<number> | string = Symbol('count') | ||
const ChildComponent = defineComponent({ | ||
setup() { | ||
const count = injectLocal(CountKey) | ||
expect(count).toBe(2333) | ||
|
||
return () => h('div') | ||
}, | ||
}) | ||
|
||
const RootComponent = defineComponent({ | ||
setup() { | ||
provideLocal(CountKey, 2333) | ||
|
||
return () => h(ChildComponent) | ||
}, | ||
}) | ||
describe('provideLocal injectLocal cross component example', () => { | ||
it('should work', () => { | ||
mount(RootComponent) | ||
}) | ||
}) | ||
} | ||
|
||
{ | ||
const CountKey: InjectionKey<number> | string = Symbol('count') | ||
const TheComponent = defineComponent({ | ||
setup() { | ||
provideLocal(CountKey, 2333) | ||
const count = injectLocal(CountKey) | ||
expect(count).toBe(2333) | ||
|
||
return () => h('div') | ||
}, | ||
}) | ||
|
||
describe('provideLocal injectLocal same component example', () => { | ||
it('should work', () => { | ||
mount(TheComponent) | ||
}) | ||
}) | ||
} |
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,3 +1,3 @@ | ||
import type { getCurrentInstance } from 'vue-demi' | ||
|
||
export const localProvidedStateMap = new WeakMap<NonNullable<ReturnType<typeof getCurrentInstance>>, Record<string | symbol, any>>() | ||
export const localProvidedStateMap = new WeakMap<NonNullable<NonNullable<ReturnType<typeof getCurrentInstance>>['proxy']>, Record<string | symbol, any>>() |