neo.mjs 4.0.9 → 4.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/data/Store.mjs
CHANGED
|
@@ -29,6 +29,23 @@ class Store extends Base {
|
|
|
29
29
|
* @protected
|
|
30
30
|
*/
|
|
31
31
|
ntype: 'store',
|
|
32
|
+
/**
|
|
33
|
+
* Instead of setting an url, you can define the RPC BE API methods.
|
|
34
|
+
* In case the 4 methods are using the same service and this service is using the CRUD based fn-names,
|
|
35
|
+
* you can switch to a string based shortcut.
|
|
36
|
+
* The following 2 examples are equivalent.
|
|
37
|
+
* @example
|
|
38
|
+
* api: {
|
|
39
|
+
* create : 'MyApp.backend.UserService.create',
|
|
40
|
+
* destroy: 'MyApp.backend.UserService.destroy',
|
|
41
|
+
* read : 'MyApp.backend.UserService.read',
|
|
42
|
+
* update : 'MyApp.backend.UserService.update'
|
|
43
|
+
* }
|
|
44
|
+
* @example
|
|
45
|
+
* api: 'MyApp.backend.UserService'
|
|
46
|
+
* @member {Object|String|null} api_=null
|
|
47
|
+
*/
|
|
48
|
+
api_: null,
|
|
32
49
|
/**
|
|
33
50
|
* @member {Boolean} autoLoad=false
|
|
34
51
|
*/
|
|
@@ -143,6 +160,25 @@ class Store extends Base {
|
|
|
143
160
|
}
|
|
144
161
|
}
|
|
145
162
|
|
|
163
|
+
/**
|
|
164
|
+
* @param {Object|String|null} value
|
|
165
|
+
* @param {Object|String|null} oldValue
|
|
166
|
+
* @protected
|
|
167
|
+
* @returns {Object|null}
|
|
168
|
+
*/
|
|
169
|
+
beforeSetApi(value, oldValue) {
|
|
170
|
+
if (Neo.typeOf(value) === 'String') {
|
|
171
|
+
value = {
|
|
172
|
+
create : value + '.create',
|
|
173
|
+
destroy: value + '.destroy',
|
|
174
|
+
read : value + '.read',
|
|
175
|
+
update : value + '.update'
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return value;
|
|
180
|
+
}
|
|
181
|
+
|
|
146
182
|
/**
|
|
147
183
|
* @param value
|
|
148
184
|
* @param oldValue
|
|
@@ -187,8 +223,8 @@ class Store extends Base {
|
|
|
187
223
|
}
|
|
188
224
|
|
|
189
225
|
/**
|
|
190
|
-
* @param {Neo.data.Model} value
|
|
191
|
-
* @param {Neo.data.Model} oldValue
|
|
226
|
+
* @param {Neo.data.Model|Object} value
|
|
227
|
+
* @param {Neo.data.Model|Object} oldValue
|
|
192
228
|
* @protected
|
|
193
229
|
* @returns {Neo.data.Model}
|
|
194
230
|
*/
|
|
@@ -210,14 +246,31 @@ class Store extends Base {
|
|
|
210
246
|
load() {
|
|
211
247
|
let me = this;
|
|
212
248
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
249
|
+
if (me.api) {
|
|
250
|
+
let apiArray = me.api.read.split('.'),
|
|
251
|
+
fn = apiArray.pop(),
|
|
252
|
+
service = Neo.ns(apiArray.join('.'));
|
|
253
|
+
|
|
254
|
+
if (!service) {
|
|
255
|
+
console.log('Api is not defined', this);
|
|
256
|
+
} else {
|
|
257
|
+
// todo: add params
|
|
258
|
+
|
|
259
|
+
service[fn]().then(response => {
|
|
260
|
+
me.data = response.data;
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
} else {
|
|
265
|
+
Neo.Xhr.promiseJson({
|
|
266
|
+
url: me.url
|
|
267
|
+
}).catch(err => {
|
|
268
|
+
console.log('Error for Neo.Xhr.request', err, me.id);
|
|
269
|
+
}).then(data => {
|
|
270
|
+
me.data = Array.isArray(data.json) ? data.json : data.json.data;
|
|
271
|
+
// we do not need to fire a load event => onCollectionMutate()
|
|
272
|
+
});
|
|
273
|
+
}
|
|
221
274
|
}
|
|
222
275
|
|
|
223
276
|
/**
|
|
@@ -237,12 +237,12 @@ class Socket extends Base {
|
|
|
237
237
|
case WebSocket.CLOSED:
|
|
238
238
|
case WebSocket.CLOSING:
|
|
239
239
|
me.attemptReconnect(function() {
|
|
240
|
-
me.
|
|
240
|
+
me.sendMessage(d);
|
|
241
241
|
});
|
|
242
242
|
break;
|
|
243
243
|
case WebSocket.CONNECTING:
|
|
244
244
|
me.on('open', function() {
|
|
245
|
-
me.
|
|
245
|
+
me.sendMessage(d);
|
|
246
246
|
}, me, {single: true});
|
|
247
247
|
break;
|
|
248
248
|
case WebSocket.OPEN:
|
|
@@ -62,7 +62,7 @@ class Message extends Base {
|
|
|
62
62
|
onMessage(msg) {
|
|
63
63
|
let api = Neo.manager.rpc.Api.get(`${msg.service}.${msg.method}`);
|
|
64
64
|
|
|
65
|
-
return this[`onMessage${Neo.capitalize(
|
|
65
|
+
return this[`onMessage${Neo.capitalize(api.type)}`](msg, api);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/**
|
|
@@ -108,8 +108,6 @@ class Message extends Base {
|
|
|
108
108
|
* @returns {Promise<any>}
|
|
109
109
|
*/
|
|
110
110
|
async onMessageWebsocket(msg, api) {
|
|
111
|
-
console.log('onMessageWebsocket', msg, api);
|
|
112
|
-
|
|
113
111
|
let me = this,
|
|
114
112
|
url = api.url,
|
|
115
113
|
connection = me.socketConnections[url];
|
|
@@ -120,11 +118,7 @@ class Message extends Base {
|
|
|
120
118
|
me.socketConnections[url] = connection = Neo.create(module.default, {serverAddress: url});
|
|
121
119
|
}
|
|
122
120
|
|
|
123
|
-
return await connection.promiseMessage(
|
|
124
|
-
data : msg,
|
|
125
|
-
method : api.method,
|
|
126
|
-
service: api.service
|
|
127
|
-
})
|
|
121
|
+
return await connection.promiseMessage(msg);
|
|
128
122
|
}
|
|
129
123
|
|
|
130
124
|
/**
|