frappe-ui 0.0.109 → 0.0.111
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
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
revertRowInListResource,
|
|
7
7
|
} from './listResource'
|
|
8
8
|
import { getLocal, saveLocal } from './local'
|
|
9
|
+
import { onDocUpdate } from './realtime'
|
|
9
10
|
|
|
10
11
|
let documentCache = reactive({})
|
|
11
12
|
|
|
@@ -165,8 +166,8 @@ export function createDocumentResource(options, vm) {
|
|
|
165
166
|
}
|
|
166
167
|
|
|
167
168
|
if (options.realtime && vm.$socket) {
|
|
168
|
-
vm.$socket.
|
|
169
|
-
if (
|
|
169
|
+
onDocUpdate(vm.$socket, out.doctype, (name) => {
|
|
170
|
+
if (name == out.name) {
|
|
170
171
|
out.get.fetch()
|
|
171
172
|
}
|
|
172
173
|
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { reactive } from 'vue'
|
|
2
2
|
import { getCacheKey, createResource } from './resources'
|
|
3
3
|
import { saveLocal, getLocal } from './local'
|
|
4
|
+
import { onDocUpdate } from './realtime'
|
|
4
5
|
|
|
5
6
|
let listCache = reactive({})
|
|
6
7
|
let resourcesByDocType = {}
|
|
@@ -32,6 +33,7 @@ export function createListResource(options, vm) {
|
|
|
32
33
|
parent: options.parent,
|
|
33
34
|
debug: options.debug || 0,
|
|
34
35
|
originalData: null,
|
|
36
|
+
dataMap: {},
|
|
35
37
|
data: null,
|
|
36
38
|
previous,
|
|
37
39
|
hasPreviousPage: false,
|
|
@@ -180,6 +182,7 @@ export function createListResource(options, vm) {
|
|
|
180
182
|
reload,
|
|
181
183
|
setData,
|
|
182
184
|
transform,
|
|
185
|
+
getRow,
|
|
183
186
|
})
|
|
184
187
|
|
|
185
188
|
function update(updatedOptions) {
|
|
@@ -227,6 +230,15 @@ export function createListResource(options, vm) {
|
|
|
227
230
|
data = data.call(vm, out.data)
|
|
228
231
|
}
|
|
229
232
|
out.data = transform(data)
|
|
233
|
+
|
|
234
|
+
if (Array.isArray(out.data)) {
|
|
235
|
+
out.dataMap = {}
|
|
236
|
+
for (let row of out.data) {
|
|
237
|
+
if (!row.name) continue
|
|
238
|
+
let key = row.name.toString()
|
|
239
|
+
out.dataMap[key] = row
|
|
240
|
+
}
|
|
241
|
+
}
|
|
230
242
|
}
|
|
231
243
|
|
|
232
244
|
function previous() {
|
|
@@ -239,13 +251,15 @@ export function createListResource(options, vm) {
|
|
|
239
251
|
out.list.fetch()
|
|
240
252
|
}
|
|
241
253
|
|
|
254
|
+
function getRow(name) {
|
|
255
|
+
let key = name.toString()
|
|
256
|
+
return out.dataMap[key]
|
|
257
|
+
}
|
|
258
|
+
|
|
242
259
|
if (options.realtime && vm.$socket) {
|
|
243
|
-
vm.$socket.
|
|
244
|
-
if (
|
|
245
|
-
|
|
246
|
-
out.originalData?.find((d) => d.name === data.name)
|
|
247
|
-
) {
|
|
248
|
-
out.fetchOne.submit(data.name)
|
|
260
|
+
onDocUpdate(vm.$socket, out.doctype, (name) => {
|
|
261
|
+
if (out.originalData?.find((d) => d.name === name)) {
|
|
262
|
+
out.fetchOne.submit(name)
|
|
249
263
|
}
|
|
250
264
|
})
|
|
251
265
|
}
|
|
@@ -302,7 +316,7 @@ export function deleteRowInListResource(doctype, docname) {
|
|
|
302
316
|
for (let resource of resources) {
|
|
303
317
|
if (resource.originalData) {
|
|
304
318
|
resource.originalData = resource.originalData.filter(
|
|
305
|
-
(row) => row.name.toString() !== docname
|
|
319
|
+
(row) => row.name.toString() !== docname.toString()
|
|
306
320
|
)
|
|
307
321
|
resource.data = resource.transform(resource.originalData)
|
|
308
322
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function onDocUpdate(socket, doctype, callback) {
|
|
2
|
+
subscribe(socket, doctype)
|
|
3
|
+
socket.on('list_update', (data) => {
|
|
4
|
+
if (data.doctype == doctype) {
|
|
5
|
+
callback(data.name)
|
|
6
|
+
}
|
|
7
|
+
})
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
let subscribed = {}
|
|
11
|
+
function subscribe(socket, doctype) {
|
|
12
|
+
if (subscribed[doctype]) return
|
|
13
|
+
socket.emit('doctype_subscribe', doctype)
|
|
14
|
+
subscribed[doctype] = true
|
|
15
|
+
}
|
|
@@ -86,9 +86,7 @@ export function createResource(options, vm) {
|
|
|
86
86
|
try {
|
|
87
87
|
invalidMessage = await validateFunction.call(vm, out.params)
|
|
88
88
|
if (invalidMessage && typeof invalidMessage == 'string') {
|
|
89
|
-
|
|
90
|
-
handleError(error, errorFunctions)
|
|
91
|
-
return
|
|
89
|
+
throw new Error(invalidMessage)
|
|
92
90
|
}
|
|
93
91
|
} catch (error) {
|
|
94
92
|
handleError(error, errorFunctions)
|