foobara-typescript-remote-command-generator 1.3.0 → 1.3.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/templates/base/QueryCache.ts +48 -0
- data/templates/base/RemoteCommand.ts.erb +7 -13
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cf59c3786304e34b238364d087ca029225bd01bf158bf9ddb928112aa8e3a234
|
|
4
|
+
data.tar.gz: 6b3fdc12eb0c6d9f4391b12ea5ed9b351ef90a48cf0aad1e8fa30288f56c7163
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7c0b909fc48ecdeb842417d9b6b4f04ad556771c2dc949775e555ff6fd1f1f1f94b820e222246135abb51a5bcb737771028c5c2e68c160a6e1358e61e71dec20
|
|
7
|
+
data.tar.gz: 64881ffe38ce0ce810b73bdc7a6d71fce9c7400979da2794a550403c2c1f81c19df4b9810f2c99fd003803c09400c0b3cf2be9df5aa5ddf8db84e96f48a4852e
|
data/CHANGELOG.md
CHANGED
|
@@ -38,6 +38,54 @@ export function forEachQuery (callback: (query: Query<RemoteCommand<any, any, an
|
|
|
38
38
|
queryCache.forEach(callback)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
interface DirtyQueryEvent {
|
|
42
|
+
commandName: string
|
|
43
|
+
propertyName: string | undefined
|
|
44
|
+
value: string | number | undefined
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let dirtyQueryChannel: BroadcastChannel | null = null
|
|
48
|
+
|
|
49
|
+
if (typeof BroadcastChannel !== 'undefined') {
|
|
50
|
+
dirtyQueryChannel = new BroadcastChannel('dirty-query')
|
|
51
|
+
|
|
52
|
+
dirtyQueryChannel.addEventListener('message', (event: MessageEvent<DirtyQueryEvent>) => {
|
|
53
|
+
const { commandName, propertyName, value } = event.data
|
|
54
|
+
|
|
55
|
+
dirtyQuery(commandName, propertyName, value, { skipBroadcast: true })
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function dirtyQuery<CommandT extends RemoteCommand<any, any, any>> (
|
|
60
|
+
commandClass: RemoteCommandConstructor<CommandT> | string,
|
|
61
|
+
propertyName: string | undefined = undefined,
|
|
62
|
+
propertyValue: string | number | undefined = undefined,
|
|
63
|
+
options: { skipBroadcast: boolean } = { skipBroadcast: false }) {
|
|
64
|
+
if (typeof commandClass !== 'string') {
|
|
65
|
+
commandClass = commandClass.fullCommandName
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
forEachQuery((query) => {
|
|
69
|
+
if (query.CommandClass.fullCommandName === commandClass) {
|
|
70
|
+
if (query.inputs == null || Object.keys(query.inputs).length === 0) {
|
|
71
|
+
query.setDirty()
|
|
72
|
+
} else {
|
|
73
|
+
if (propertyName != null) {
|
|
74
|
+
if (query.inputs[propertyName] !== propertyValue) {
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
query.setDirty()
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
if (dirtyQueryChannel != null && !options.skipBroadcast) {
|
|
85
|
+
dirtyQueryChannel.postMessage({ commandName: commandClass, propertyName, value: propertyValue })
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
41
89
|
function toKey<CommandT extends RemoteCommand<any, any, any>> (
|
|
42
90
|
CommandClass: RemoteCommandConstructor<CommandT>,
|
|
43
91
|
inputs: InputsOf<CommandT> | undefined
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Outcome, SuccessfulOutcome, ErrorOutcome } from './Outcome'
|
|
2
2
|
import { type FoobaraError } from './Error'
|
|
3
3
|
<% if auto_dirty_queries? %>
|
|
4
|
-
import
|
|
4
|
+
import { dirtyQuery } from './QueryCache'
|
|
5
5
|
<% end %>
|
|
6
6
|
|
|
7
7
|
export default abstract class RemoteCommand<Inputs, Result, CommandError extends FoobaraError> {
|
|
@@ -136,19 +136,13 @@ export default abstract class RemoteCommand<Inputs, Result, CommandError extends
|
|
|
136
136
|
<% if auto_dirty_queries? %>
|
|
137
137
|
dirtyQueries () {
|
|
138
138
|
for (const [commandClass, inputs] of this.dirties()) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (inputs == null || Object.keys(inputs).length === 0) {
|
|
143
|
-
query.setDirty()
|
|
144
|
-
} else {
|
|
145
|
-
for (const [property, value] of Object.entries(inputs)) {
|
|
146
|
-
if (query.inputs[property] !== value) { return }
|
|
147
|
-
}
|
|
148
|
-
query.setDirty()
|
|
149
|
-
}
|
|
139
|
+
if (inputs != null) {
|
|
140
|
+
for (const [propertyName, value] of Object.entries(inputs)) {
|
|
141
|
+
dirtyQuery(commandClass, propertyName, value)
|
|
150
142
|
}
|
|
151
|
-
}
|
|
143
|
+
} else {
|
|
144
|
+
dirtyQuery(commandClass)
|
|
145
|
+
}
|
|
152
146
|
}
|
|
153
147
|
}
|
|
154
148
|
<% end %>
|