@@ -5,7 +5,9 @@ const defaultOptions = {
55
66export default {
77 install ( components , installOptions ) {
8- const pluginOptions = { ...defaultOptions , ...installOptions } ;
8+ const pluginOptions = { ...defaultOptions ,
9+ ...installOptions
10+ } ;
911
1012 const {
1113 Model,
@@ -28,7 +30,7 @@ export default {
2830 const _saveFillMethod = Model . prototype . $fill ;
2931
3032 // Overwrite
31- Model . prototype . $fill = function ( record ) {
33+ Model . prototype . $fill = function ( record ) {
3234 _saveFillMethod . call ( this , record ) ; // Calling initial
3335
3436 // $isDirty
@@ -45,15 +47,15 @@ export default {
4547 * This is the only automatic way which sets this flag
4648 * to true once it's in the store.
4749 */
48- Query . on ( 'beforeUpdate' , function ( model ) {
50+ Query . on ( 'beforeUpdate' , function ( model ) {
4951 model [ pluginOptions . isDirtyFlagName ] = true ;
5052 } ) ;
5153
5254 /**
5355 * Providing the allDirty getter
5456 */
55- RootGetters . allDirty = function ( state ) {
56- return function ( entity ) {
57+ RootGetters . allDirty = function ( state ) {
58+ return function ( entity ) {
5759 if ( entity ) {
5860 return new Query ( state , entity )
5961 . where ( elt => elt [ pluginOptions . isDirtyFlagName ] )
@@ -72,8 +74,8 @@ export default {
7274 } ;
7375 } ;
7476
75- Getters . allDirty = function ( state , _getters , _rootState , rootGetters ) {
76- return function ( ) {
77+ Getters . allDirty = function ( state , _getters , _rootState , rootGetters ) {
78+ return function ( ) {
7779 return rootGetters [ `${ state . $connection } /allDirty` ] (
7880 state . $name
7981 ) ;
@@ -83,8 +85,8 @@ export default {
8385 /**
8486 * Providing the allNew getter
8587 */
86- RootGetters . allNew = function ( state ) {
87- return function ( entity ) {
88+ RootGetters . allNew = function ( state ) {
89+ return function ( entity ) {
8890 if ( entity ) {
8991 return new Query ( state , entity )
9092 . where ( elt => elt [ pluginOptions . isNewFlagName ] )
@@ -103,8 +105,8 @@ export default {
103105 } ;
104106 } ;
105107
106- Getters . allNew = function ( state , _getters , _rootState , rootGetters ) {
107- return function ( ) {
108+ Getters . allNew = function ( state , _getters , _rootState , rootGetters ) {
109+ return function ( ) {
108110 return rootGetters [ `${ state . $connection } /allNew` ] ( state . $name ) ;
109111 } ;
110112 } ;
@@ -114,17 +116,17 @@ export default {
114116 * When called on the Model instead of new, it will
115117 * set the 2 flags to true
116118 */
117- Model . createNew = function ( insertInStore = true ) {
119+ Model . createNew = function ( insertInStore = true ) {
118120 if ( insertInStore ) return this . dispatch ( 'createNew' ) ;
119121 else {
120122 let record = new this ( ) ;
121123 record [ pluginOptions . isNewFlagName ] = true ;
122124 record [ pluginOptions . isDirtyFlagName ] = true ;
123- return record ;
125+ return Promise . resolve ( record ) ;
124126 }
125127 } ;
126128
127- RootMutations . createNew = function ( state , payload ) {
129+ RootMutations . createNew = function ( state , payload ) {
128130 const entity = payload . entity ;
129131 const result = payload . result ;
130132
@@ -133,19 +135,23 @@ export default {
133135 query . setResult ( result ) . createNew ( ) ;
134136 } ;
135137
136- Actions . createNew = function ( context ) {
138+ Actions . createNew = function ( context ) {
137139 const state = context . state ;
138140 const entity = state . $name ;
139141
140142 return context . dispatch (
141- `${ state . $connection } /createNew` ,
142- { entity } ,
143- { root : true }
143+ `${ state . $connection } /createNew` , {
144+ entity
145+ } , {
146+ root : true
147+ }
144148 ) ;
145149 } ;
146150
147- RootActions . createNew = function ( context , payload ) {
148- const result = { data : { } } ;
151+ RootActions . createNew = function ( context , payload ) {
152+ const result = {
153+ data : { }
154+ } ;
149155
150156 context . commit ( 'createNew' , {
151157 ...payload ,
@@ -155,7 +161,7 @@ export default {
155161 return result . data ;
156162 } ;
157163
158- Query . prototype . createNew = function ( ) {
164+ Query . prototype . createNew = function ( ) {
159165 let record = new this . model ( ) . $toJson ( ) ;
160166
161167 record [ pluginOptions . isNewFlagName ] = true ;
@@ -168,4 +174,4 @@ export default {
168174 return this . result . data ;
169175 } ;
170176 }
171- } ;
177+ } ;
0 commit comments