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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63a56366d8d763f7a5945acb31f26942889b8801d87d473f1cf80670492984ea
4
- data.tar.gz: f743ce22ffdf47ece2df4d68763a76c959072098fb50c2314da236c667cbc7e6
3
+ metadata.gz: cf59c3786304e34b238364d087ca029225bd01bf158bf9ddb928112aa8e3a234
4
+ data.tar.gz: 6b3fdc12eb0c6d9f4391b12ea5ed9b351ef90a48cf0aad1e8fa30288f56c7163
5
5
  SHA512:
6
- metadata.gz: 3296bab04a57c964281ee3e8b5e4b5db4f3cda345bfbbbf6c9667cbc1eba4cd2e75266a1be6d9cc38836d44b310355201f4590bec04fcf87a33f96e7e988c6fd
7
- data.tar.gz: 18a1e5716e44579286b0251cbc9b30fc4814c5c7033578ff33d00b91a6640e7e20042acc0a93ded4ff2cc4d001c310f605a3eed448c839d7391b40dad0abf6ea
6
+ metadata.gz: 7c0b909fc48ecdeb842417d9b6b4f04ad556771c2dc949775e555ff6fd1f1f1f94b820e222246135abb51a5bcb737771028c5c2e68c160a6e1358e61e71dec20
7
+ data.tar.gz: 64881ffe38ce0ce810b73bdc7a6d71fce9c7400979da2794a550403c2c1f81c19df4b9810f2c99fd003803c09400c0b3cf2be9df5aa5ddf8db84e96f48a4852e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [1.3.1] - 2026-02-28
2
+
3
+ - Use a channel to make other tabs automatically reload their queries
4
+
1
5
  ## [1.3.0] - 2026-02-26
2
6
 
3
7
  - Add auto-dirty queries feature
@@ -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 * as QueryCache from './QueryCache'
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
- QueryCache.forEachQuery((query) => {
140
- // debugger
141
- if (query.CommandClass === commandClass) {
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 %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-typescript-remote-command-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi