@logux/vuex
Advanced tools
Comparing version
# Change Log | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
## 0.9.2 | ||
* `useSubscription`’s argument `channels` can be a getter function | ||
## 0.9.1 | ||
@@ -5,0 +8,0 @@ * Fix Typescript exports |
@@ -1,2 +0,6 @@ | ||
import { Ref, ComputedRef } from 'vue' | ||
import { | ||
Ref, | ||
ComputedGetter, | ||
ComputedRef | ||
} from '@vue/reactivity' | ||
@@ -11,2 +15,3 @@ export type Channel = | ||
export type Channels = | ||
| ComputedGetter<Channel[]> | ||
| ComputedRef<Channel[]> | ||
@@ -40,6 +45,4 @@ | Channel[] | ||
* let { userId } = toRefs(props) | ||
* let isSubscribing = useSubscription(() => [`user/${userId}`]) | ||
* | ||
* let channels = computed(() => [`user/${userId}`]) | ||
* let isSubscribing = useSubscription(channels) | ||
* | ||
* let user = computed(() => store.state.users[userId]) | ||
@@ -46,0 +49,0 @@ * |
@@ -11,2 +11,4 @@ import { useStore } from 'vuex' | ||
import { isFunction } from '../utils/index.js' | ||
function useSubscription (channels) { | ||
@@ -16,4 +18,6 @@ let isSubscribing = ref(true) | ||
if (isRef(channels)) { | ||
let subscriptions = computed(() => unifyChannelsObject(channels.value)) | ||
if (isRef(channels) || isFunction(channels)) { | ||
let channelsRef = isFunction(channels) ? computed(channels) : channels | ||
let subscriptions = computed(() => unifyChannelsObject(channelsRef.value)) | ||
let id = computed(() => subscriptionsId(subscriptions.value)) | ||
@@ -20,0 +24,0 @@ |
{ | ||
"name": "@logux/vuex", | ||
"version": "0.9.1", | ||
"version": "0.9.2", | ||
"description": "Vuex compatible API for Logux", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -81,3 +81,3 @@ # Logux Vuex | ||
<script> | ||
import { toRefs, computed } from 'vue' | ||
import { toRefs } from 'vue' | ||
import { useStore, useSubscription } from '@logux/vuex' | ||
@@ -92,6 +92,4 @@ | ||
let { userId } = toRefs(props) | ||
let isSubscribing = useSubscription(() => [`user/${userId}`]) | ||
let channels = computed(() => [`user/${userId}`]) | ||
let isSubscribing = useSubscription(channels) | ||
let user = computed(() => store.state.users[userId]) | ||
@@ -98,0 +96,0 @@ |
@@ -202,2 +202,5 @@ import { Unsubscribe } from 'nanoevents' | ||
*/ | ||
export function createStoreCreator(client: Client | CrossTabClient, options?: LoguxVuexOptions): createStore | ||
export function createStoreCreator( | ||
client: Client | CrossTabClient, | ||
options?: LoguxVuexOptions | ||
): createStore |
@@ -11,7 +11,7 @@ import { createNanoEvents } from 'nanoevents' | ||
function createStoreCreator (client, config = {}) { | ||
let reasonlessHistory = config.reasonlessHistory || 1000 | ||
let saveStateEvery = config.saveStateEvery || 50 | ||
let onMissedHistory = config.onMissedHistory | ||
let cleanEvery = config.cleanEvery || 25 | ||
function createStoreCreator (client, options = {}) { | ||
let reasonlessHistory = options.reasonlessHistory || 1000 | ||
let onMissedHistory = options.onMissedHistory | ||
let saveStateEvery = options.saveStateEvery || 50 | ||
let cleanEvery = options.cleanEvery || 25 | ||
@@ -53,3 +53,3 @@ let log = client.log | ||
function originCommit (action, options) { | ||
function originCommit (action, opts) { | ||
if (action.type === 'logux/state') { | ||
@@ -61,6 +61,6 @@ store.replaceState(action.state) | ||
if (hasSimplePayload(action)) { | ||
storeCommit(action.type, action.payload, options) | ||
storeCommit(action.type, action.payload, opts) | ||
return | ||
} | ||
storeCommit(action, options) | ||
storeCommit(action, opts) | ||
} | ||
@@ -70,3 +70,3 @@ } | ||
store.commit = (type, payload, _options) => { | ||
let { action, options } = unifyCommitArgs(type, payload, _options) | ||
let { action, options: commitOpts } = unifyCommitArgs(type, payload, _options) | ||
let meta = { | ||
@@ -82,3 +82,3 @@ id: log.generateId(), | ||
let prevState = deepCopy(store.state) | ||
originCommit(action, options) | ||
originCommit(action, commitOpts) | ||
emitter.emit('change', deepCopy(store.state), prevState, action, meta) | ||
@@ -85,0 +85,0 @@ saveHistory(meta) |
@@ -36,2 +36,6 @@ function find (list, f) { | ||
function isFunction (val) { | ||
return typeof val === 'function' | ||
} | ||
export { | ||
@@ -41,3 +45,4 @@ find, | ||
isPromise, | ||
isFunction, | ||
forEachValue | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
52524
1.05%1426
1.28%163
-1.21%