Skip to content

Commit 9adffc3

Browse files
committed
Update FeathersVuexFormWrapper docs
This closes #353 Gives two better integration examples of the FeathersVuexFormWrapper
1 parent 5808eee commit 9adffc3

File tree

1 file changed

+72
-12
lines changed

1 file changed

+72
-12
lines changed

docs/feathers-vuex-form-wrapper.md

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,79 @@ Send most edits through a single mutation can really simplify the way you work w
3131

3232
The `FeathersVuexFormWrapper` component uses the "clone and commit" pattern to connect a single record to a child form within its default slot.
3333

34-
```html
35-
<FeathersVuexFormWrapper :item="currentItem" watch>
36-
<template v-slot="{ clone, save, reset, remove }">
37-
<SomeEditor
38-
:item="clone"
39-
@save="save"
40-
@reset="reset"
41-
@remove="remove"
42-
></SomeEditor>
43-
</template>
44-
</FeathersVuexFormWrapper>
34+
```vue
35+
<template>
36+
<FeathersVuexFormWrapper :item="currentItem" watch>
37+
<template v-slot="{ clone, save, reset, remove }">
38+
<SomeEditor
39+
:item="clone"
40+
@save="save({ /* params object */ }).then(handleSaveResponse)"
41+
@reset="reset"
42+
@remove="remove"
43+
></SomeEditor>
44+
</template>
45+
</FeathersVuexFormWrapper>
46+
</template>
47+
48+
<script>
49+
export default {
50+
name: 'MyComponent',
51+
props: {
52+
currentItem: {
53+
type: Object,
54+
required: true
55+
}
56+
},
57+
methods: {
58+
handleSaveReponse(savedItem) {
59+
console.log(savedItem) // The item returned from the API call
60+
}
61+
}
62+
}
63+
</script>
4564
```
4665

66+
Here's another example of how you could use the form wrapper to both save the form and close a modal at the same time. (The modal is not shown in the template markup.) Notice how the `@save` handler is an inline function that sets `isModalVisible` to false, then on a new line it calls save. This is handled perfectly by Vue.
67+
68+
```vue
69+
<template>
70+
<FeathersVuexFormWrapper :item="currentItem" watch>
71+
<template v-slot="{ clone, save, reset, remove }">
72+
<SomeEditor
73+
:item="clone"
74+
@save="
75+
() => {
76+
isModalVisible = false
77+
save({ populateParams: {} })
78+
}
79+
"
80+
@reset="reset"
81+
@remove="remove"
82+
></SomeEditor>
83+
</template>
84+
</FeathersVuexFormWrapper>
85+
</template>
86+
87+
<script>
88+
export default {
89+
name: 'MyComponent',
90+
props: {
91+
currentItem: {
92+
type: Object,
93+
required: true
94+
}
95+
},
96+
data: () => ({
97+
isModalVisible: true
98+
}),
99+
methods: {
100+
handleSaveReponse(savedItem) {
101+
console.log(savedItem) // The item returned from the API call
102+
}
103+
}
104+
}
105+
</script>
106+
```
47107
### Props
48108

49109
- `item`: {Object} a model instance from the Vuex store.
@@ -55,6 +115,6 @@ The `FeathersVuexFormWrapper` component uses the "clone and commit" pattern to c
55115
The default slot contains only four attributes. The `clone` data can be passed to the child component. The `save`, `reset`, and `remove` are meant to be bound to events emitted from the child component.
56116

57117
- `clone`: {Object} The cloned record. Each record in the store can have a single clone. The clones are stored on the service's model class, by default.
58-
- `save`: {Function} When called, it commits the data and saves the record (with eager updating, by default. See the `eager` prop.).
118+
- `save`: {Function} When called, it commits the data and saves the record (with eager updating, by default. See the `eager` prop.) The save method calls `instance.save()`, internally, so you can pass a params object, if needed.
59119
- `reset`: {Function} When called, the clone data will be reset back to the data that is currently found in the store for the same record.
60120
- `remove`: {Function} When called, it removes the record from the API server and the Vuex store.

0 commit comments

Comments
 (0)