ar_sync 1.1.2 → 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,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - tompng
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-07-29 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activerecord
@@ -114,8 +113,8 @@ files:
114
113
  - core/hooks.d.ts
115
114
  - core/hooks.js
116
115
  - gemfiles/Gemfile-rails-6
117
- - gemfiles/Gemfile-rails-7-0
118
- - gemfiles/Gemfile-rails-7-1
116
+ - gemfiles/Gemfile-rails-7
117
+ - gemfiles/Gemfile-rails-8
119
118
  - index.d.ts
120
119
  - index.js
121
120
  - lib/ar_sync.rb
@@ -147,7 +146,6 @@ homepage: https://github.com/tompng/ar_sync
147
146
  licenses:
148
147
  - MIT
149
148
  metadata: {}
150
- post_install_message:
151
149
  rdoc_options: []
152
150
  require_paths:
153
151
  - lib
@@ -162,8 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
160
  - !ruby/object:Gem::Version
163
161
  version: '0'
164
162
  requirements: []
165
- rubygems_version: 3.5.9
166
- signing_key:
163
+ rubygems_version: 4.0.3
167
164
  specification_version: 4
168
165
  summary: ActiveRecord - JavaScript Sync
169
166
  test_files: []