Skip to content

Commit

Permalink
feat: make it work with vue 3
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Dec 21, 2019
1 parent 6e4ae12 commit 54505cb
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 150 deletions.
1 change: 1 addition & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"tokenRef": "GITHUB_TOKEN"
},
"npm": {
"tag": "next",
"publish": true
},
"changelogCommand": "git log --pretty=format:'* %s (%h)' [REV_RANGE]"
Expand Down
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
"eslint.validate": [
"javascript",
{ "language": "typescript", "autoFix": true }
]
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
6 changes: 0 additions & 6 deletions __tests__/setup.ts

This file was deleted.

1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module.exports = {
collectCoverage: true,
collectCoverageFrom: ['<rootDir>/src/**/*.ts'],
testMatch: ['<rootDir>/__tests__/**/*.spec.ts'],
setupFilesAfterEnv: ['./__tests__/setup.ts'],
globals: {
'ts-jest': {
diagnostics: {
Expand Down
3 changes: 2 additions & 1 deletion __tests__/ssr/app.spec.ts → old test ssr/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { createRenderer } from 'vue-server-renderer'

const renderer = createRenderer()

describe('classic vue app', () => {
// FIXME: add when ssr is available in vue 3
describe.skip('classic vue app', () => {
it('renders using the store', async () => {
const context = {
rendered: () => {},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion __tests__/ssr/app/store.ts → old test ssr/app/store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createStore } from '../../../src'
import { createStore } from '../../src'

export const useStore = createStore('main', () => ({
counter: 0,
Expand Down
31 changes: 21 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pinia",
"version": "0.0.2",
"version": "0.1.0-alpha.0",
"description": "Some awesome description",
"main": "dist/pinia.common.js",
"module": "dist/pinia.esm.js",
Expand Down Expand Up @@ -31,17 +31,29 @@
"tsd": {
"directory": "__tests__/dts"
},
"keywords": [],
"keywords": [
"vue",
"vuex",
"store",
"pina",
"composition",
"api",
"setup",
"typed",
"typescript",
"ts",
"type",
"safe"
],
"license": "MIT",
"devDependencies": {
"@rollup/plugin-alias": "^2.2.0",
"@rollup/plugin-replace": "^2.2.1",
"@types/jest": "^24.0.18",
"@typescript-eslint/eslint-plugin": "^2.10.0",
"@typescript-eslint/parser": "^2.3.1",
"@vue/composition-api": "^0.3.2",
"@types/jest": "^24.0.24",
"@typescript-eslint/eslint-plugin": "^2.12.0",
"@typescript-eslint/parser": "^2.12.0",
"codecov": "^3.6.1",
"eslint": "^6.4.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.3.0",
"eslint-plugin-prettier": "^3.1.1",
"jest": "^24.9.0",
Expand All @@ -55,9 +67,8 @@
"rollup-plugin-typescript2": "^0.25.2",
"ts-jest": "^24.1.0",
"tsd": "^0.11.0",
"typescript": "^3.6.3",
"vue": "^2.6.11",
"vue-server-renderer": "^2.6.11"
"typescript": "^3.7.4",
"vue": "next"
},
"repository": {
"type": "git",
Expand Down
12 changes: 9 additions & 3 deletions src/store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ref, watch, computed } from '@vue/composition-api'
import { Ref } from '@vue/composition-api/dist/reactivity'
import { ref, watch, computed } from 'vue'
import {
StateTree,
Store,
Expand Down Expand Up @@ -57,7 +56,7 @@ export function buildStore<
getters: G = {} as G
// methods: Record<string | symbol, StoreMethod>
): CombinedStore<Id, S, G> {
const state: Ref<S> = ref(buildState())
const state = ref<S>(buildState())

let isListening = true
let subscriptions: SubscriptionCallback<S>[] = []
Expand All @@ -67,6 +66,7 @@ export function buildStore<
state => {
if (isListening) {
subscriptions.forEach(callback => {
// @ts-ignore FIXME: why is this even failing on TS
callback({ storeName: id, type: '🧩 in place', payload: {} }, state)
})
}
Expand All @@ -79,11 +79,13 @@ export function buildStore<

function patch(partialState: DeepPartial<S>): void {
isListening = false
// @ts-ignore FIXME: why is this even failing on TS
innerPatch(state.value, partialState)
isListening = true
subscriptions.forEach(callback => {
callback(
{ storeName: id, type: '⤵️ patch', payload: partialState },
// @ts-ignore FIXME: why is this even failing on TS
state.value
)
})
Expand All @@ -96,12 +98,14 @@ export function buildStore<

function reset() {
subscriptions = []
// @ts-ignore FIXME: why is this even failing on TS
state.value = buildState()
}

const storeWithState: Store<Id, S> = {
id,
// it is replaced below by a getter
// @ts-ignore FIXME: why is this even failing on TS
state: state.value,

patch,
Expand All @@ -115,6 +119,7 @@ export function buildStore<
const method = getters[getterName]
// @ts-ignore
computedGetters[getterName] = computed<ReturnType<typeof method>>(() =>
// @ts-ignore FIXME: why is this even failing on TS
getters[getterName](state.value)
)
}
Expand All @@ -129,6 +134,7 @@ export function buildStore<
get: () => state.value,
set: (newState: S) => {
isListening = false
// @ts-ignore FIXME: why is this even failing on TS
state.value = newState
isListening = true
},
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Ref } from '@vue/composition-api'
import { Ref } from 'vue'

interface JSONSerializable {
toJSON(): string
Expand Down
Loading

0 comments on commit 54505cb

Please sign in to comment.