ar_sync 1.1.3 → 1.1.4

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.
data/package.json CHANGED
@@ -10,9 +10,9 @@
10
10
  "@types/react": "^16.8.6",
11
11
  "actioncable": "^5.2.0",
12
12
  "@types/actioncable": "^5.2.0",
13
- "eslint": "^5.16.0",
13
+ "eslint": "^9.39.1",
14
14
  "typescript": "3.9.5",
15
- "@typescript-eslint/eslint-plugin": "^1.6.0",
16
- "@typescript-eslint/parser": "^1.6.0"
15
+ "@typescript-eslint/eslint-plugin": "^8.46.4",
16
+ "@typescript-eslint/parser": "^8.46.4"
17
17
  }
18
18
  }
@@ -7,8 +7,13 @@ interface Change { path: Path; value: any }
7
7
  type ChangeCallback = (change: Change) => void
8
8
  type LoadCallback = () => void
9
9
  type ConnectionCallback = (status: boolean) => void
10
- type SubscriptionType = 'load' | 'change' | 'connection' | 'destroy'
11
- type SubscriptionCallback = ChangeCallback | LoadCallback | ConnectionCallback
10
+ type SubscriptionCallbackMap = {
11
+ load: LoadCallback
12
+ change: ChangeCallback
13
+ connection: ConnectionCallback
14
+ destroy: LoadCallback
15
+ }
16
+ type SubscriptionType = keyof SubscriptionCallbackMap
12
17
  type ArSyncModelRef = { key: string; count: number; timer: number | null; model: ArSyncStore }
13
18
 
14
19
  type PathFirst<P extends Readonly<any[]>> = ((...args: P) => void) extends (first: infer First, ...other: any) => void ? First : never
@@ -62,9 +67,9 @@ export default class ArSyncModel<T> {
62
67
  onload(callback: LoadCallback) {
63
68
  this.subscribeOnce('load', callback)
64
69
  }
65
- subscribeOnce(event: SubscriptionType, callback: SubscriptionCallback) {
66
- const subscription = this.subscribe(event, (arg) => {
67
- (callback as (arg: any) => void)(arg)
70
+ subscribeOnce<T extends SubscriptionType>(event: T, callback: SubscriptionCallbackMap[T]) {
71
+ const subscription = this.subscribe(event, (e?: any) => {
72
+ callback(e)
68
73
  subscription.unsubscribe()
69
74
  })
70
75
  return subscription
@@ -86,7 +91,7 @@ export default class ArSyncModel<T> {
86
91
  }
87
92
  return dig(data, path)
88
93
  }
89
- subscribe(event: SubscriptionType, callback: SubscriptionCallback): { unsubscribe: () => void } {
94
+ subscribe<T extends SubscriptionType>(event: T, callback: SubscriptionCallbackMap[T]): { unsubscribe: () => void } {
90
95
  const id = this._listenerSerial++
91
96
  const subscription = this._ref.model.subscribe(event, callback)
92
97
  let unsubscribed = false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - tompng
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  - !ruby/object:Gem::Version
161
161
  version: '0'
162
162
  requirements: []
163
- rubygems_version: 3.7.1
163
+ rubygems_version: 4.0.3
164
164
  specification_version: 4
165
165
  summary: ActiveRecord - JavaScript Sync
166
166
  test_files: []