neo.mjs 4.0.9 → 4.0.10
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,10 @@ class Store extends Base {
|
|
|
29
29
|
* @protected
|
|
30
30
|
*/
|
|
31
31
|
ntype: 'store',
|
|
32
|
+
/**
|
|
33
|
+
* @member {Object|String|null} api_=null
|
|
34
|
+
*/
|
|
35
|
+
api_: null,
|
|
32
36
|
/**
|
|
33
37
|
* @member {Boolean} autoLoad=false
|
|
34
38
|
*/
|
|
@@ -187,8 +191,8 @@ class Store extends Base {
|
|
|
187
191
|
}
|
|
188
192
|
|
|
189
193
|
/**
|
|
190
|
-
* @param {Neo.data.Model} value
|
|
191
|
-
* @param {Neo.data.Model} oldValue
|
|
194
|
+
* @param {Neo.data.Model|Object} value
|
|
195
|
+
* @param {Neo.data.Model|Object} oldValue
|
|
192
196
|
* @protected
|
|
193
197
|
* @returns {Neo.data.Model}
|
|
194
198
|
*/
|
|
@@ -210,14 +214,31 @@ class Store extends Base {
|
|
|
210
214
|
load() {
|
|
211
215
|
let me = this;
|
|
212
216
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
217
|
+
if (me.api) {
|
|
218
|
+
let apiArray = me.api.create.split('.'),
|
|
219
|
+
fn = apiArray.pop(),
|
|
220
|
+
service = Neo.ns(apiArray.join('.'));
|
|
221
|
+
|
|
222
|
+
if (!service) {
|
|
223
|
+
console.log('Api is not defined', this);
|
|
224
|
+
} else {
|
|
225
|
+
// todo: add params
|
|
226
|
+
|
|
227
|
+
service[fn]().then(response => {
|
|
228
|
+
me.data = response.data;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
} else {
|
|
233
|
+
Neo.Xhr.promiseJson({
|
|
234
|
+
url: me.url
|
|
235
|
+
}).catch(err => {
|
|
236
|
+
console.log('Error for Neo.Xhr.request', err, me.id);
|
|
237
|
+
}).then(data => {
|
|
238
|
+
me.data = Array.isArray(data.json) ? data.json : data.json.data;
|
|
239
|
+
// we do not need to fire a load event => onCollectionMutate()
|
|
240
|
+
});
|
|
241
|
+
}
|
|
221
242
|
}
|
|
222
243
|
|
|
223
244
|
/**
|
|
@@ -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
|
/**
|