-
-
Notifications
You must be signed in to change notification settings - Fork 978
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: access the state and getters through
this
(#190)
BREAKING CHANGE: there is no longer a `state` property on the store, you need to directly access it. `getters` no longer receive parameters, directly call `this.myState` to read state and other getters
- Loading branch information
Showing
10 changed files
with
196 additions
and
98 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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createStore, setActiveReq } from '../src' | ||
import { computed } from '@vue/composition-api' | ||
|
||
describe('State', () => { | ||
const useStore = () => { | ||
// create a new store | ||
setActiveReq({}) | ||
return createStore({ | ||
id: 'main', | ||
state: () => ({ | ||
name: 'Eduardo', | ||
counter: 0, | ||
}), | ||
})() | ||
} | ||
|
||
it('can directly access state at the store level', () => { | ||
const store = useStore() | ||
expect(store.name).toBe('Eduardo') | ||
store.name = 'Ed' | ||
expect(store.name).toBe('Ed') | ||
}) | ||
|
||
it('state is reactive', () => { | ||
const store = useStore() | ||
const upperCased = computed(() => store.name.toUpperCase()) | ||
expect(upperCased.value).toBe('EDUARDO') | ||
store.name = 'Ed' | ||
expect(upperCased.value).toBe('ED') | ||
}) | ||
}) |
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,4 +1,4 @@ | ||
export { createStore } from './store' | ||
export { setActiveReq, setStateProvider, getRootState } from './rootStore' | ||
export { StateTree, StoreGetter, Store } from './types' | ||
export { StateTree, Store } from './types' | ||
export { PiniaSsr } from './ssrPlugin' |
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
Oops, something went wrong.