Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make service actions options args vue demi #583

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function makeServiceModule(
state: makeDefaultState(options),
getters: makeGetters(),
mutations: options.makeServiceMutations(),
actions: makeActions(service),
actions: makeActions({service, options}),
}
const merged = _merge({}, defaults, fromOptions)
const extended = options.extend({ store, module: merged })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ eslint
import fastCopy from 'fast-copy'
import { getId } from '../utils'
import { Service } from '@feathersjs/feathers'
import { MakeServicePluginOptions } from './types'

export default function makeServiceActions(service: Service<any>) {
interface serviceAndOptions {
service: Service<any>
options: MakeServicePluginOptions
}

export default function makeServiceActions({service, options}: serviceAndOptions) {
const serviceActions = {
find({ commit, dispatch }, params) {
params = params || {}
Expand Down Expand Up @@ -167,8 +173,8 @@ export default function makeServiceActions(service: Service<any>) {

params = fastCopy(params)

if (service.FeathersVuexModel && (!params || !params.data)) {
data = service.FeathersVuexModel.diffOnPatch(data)
if (options.Model && (!params || !params.data)) {
data = options.Model.diffOnPatch(data)
}
if (params && params.data) {
data = params.data
Expand Down Expand Up @@ -316,9 +322,9 @@ export default function makeServiceActions(service: Service<any>) {
commit('removeItems', toRemove) // commit removal
}

if (service.FeathersVuexModel) {
if (options.Model) {
toAdd.forEach((item, index) => {
toAdd[index] = new service.FeathersVuexModel(item, { commit: false })
toAdd[index] = new options.Model(item, { commit: false })
})
}

Expand All @@ -341,8 +347,8 @@ export default function makeServiceActions(service: Service<any>) {

const isIdOk = id !== null && id !== undefined

if (service.FeathersVuexModel && !(item instanceof service.FeathersVuexModel)) {
item = new service.FeathersVuexModel(item, { commit: false })
if (options.Model && !(item instanceof options.Model)) {
item = new options.Model(item, { commit: false })
}

if (isIdOk) {
Expand Down