dexiecable 0.1.5 → 0.1.6
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/README.md +11 -11
- data/lib/dexiecable/active_record_ext.rb +4 -4
- data/lib/dexiecable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9b4a75838a91bf8b9ef988b1b2ef14f90e2148df75d80b15127487bb3b9efb8e
|
|
4
|
+
data.tar.gz: 99ca5b8a8cf6a4b12eca7d54753b0de8c35dc699c22bb172a62b7ca826fa9f6a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d77d14a92756f3a05c4c038f93f542953036d3df2e010952659a4833a48997fef2fcf4d145360f03d684a40b8fc25715a3aaf8f5624ff0f6bc3934568ff5806c
|
|
7
|
+
data.tar.gz: ae7f67b4bf0ab26883afd3ba7c17fc944b6f7fc66f0f862c0c6cec6ff9d494ed749b2436e47d80898dc86d11ed1c44235e679e68b4ff3e9c1b662552e2536b59
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Run [Dexie.js](https://dexie.org) IndexedDB operations from your Rails ActionCable channels.
|
|
4
4
|
|
|
5
|
-
DexieCable augments ActionCable channels with a query DSL that mirrors the Dexie.js API, letting you push database mutations from the server to the client in real time. It also gives you a `
|
|
5
|
+
DexieCable augments ActionCable channels with a query DSL that mirrors the Dexie.js API, letting you push database mutations from the server to the client in real time. It also gives you a `syncs_to_dexie` ActiveRecord macro for automatic change syncing.
|
|
6
6
|
|
|
7
7
|
You can run any Dexie table update directly inside a channel:
|
|
8
8
|
|
|
@@ -29,11 +29,11 @@ class NotificationsController < ApplicationController
|
|
|
29
29
|
end
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
An even more convenient way is to use the `
|
|
32
|
+
An even more convenient way is to use the `syncs_to_dexie` macro:
|
|
33
33
|
|
|
34
34
|
```ruby
|
|
35
35
|
class Notification < ApplicationRecord
|
|
36
|
-
|
|
36
|
+
syncs_to_dexie via: UserChannel, subject: :user
|
|
37
37
|
end
|
|
38
38
|
```
|
|
39
39
|
|
|
@@ -47,7 +47,7 @@ Add to your `Gemfile`:
|
|
|
47
47
|
gem "dexiecable"
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
Then `bundle install`. The Railtie automatically extends `ActiveRecord::Base` with `
|
|
50
|
+
Then `bundle install`. The Railtie automatically extends `ActiveRecord::Base` with `syncs_to_dexie`.
|
|
51
51
|
|
|
52
52
|
### npm package
|
|
53
53
|
|
|
@@ -123,21 +123,21 @@ UserChannel[current_user]
|
|
|
123
123
|
|
|
124
124
|
The full query chain is serialized as JSON and sent over ActionCable. The JS client replays every method call against the local Dexie database in order.
|
|
125
125
|
|
|
126
|
-
### `
|
|
126
|
+
### `syncs_to_dexie` — automatic model syncing
|
|
127
127
|
|
|
128
128
|
Add to any ActiveRecord model. `subject` is what gets passed to `broadcast_to` as the stream target:
|
|
129
129
|
|
|
130
130
|
```ruby
|
|
131
131
|
class Message < ApplicationRecord
|
|
132
132
|
# Calls send(:receiver), then broadcasts: broadcast_to(receiver, ...)
|
|
133
|
-
|
|
133
|
+
syncs_to_dexie via: UserChannel, subject: :receiver
|
|
134
134
|
|
|
135
135
|
# String used directly: broadcast_to("global_feed", ...)
|
|
136
|
-
|
|
136
|
+
syncs_to_dexie via: UserChannel, subject: "global_feed"
|
|
137
137
|
|
|
138
138
|
# Procs are also supported. If an array is returned, multiple broadcasts are made
|
|
139
139
|
# conversation.users.each { |u| broadcast_to(u, ...) }
|
|
140
|
-
|
|
140
|
+
syncs_to_dexie via: UserChannel, subject: -> { conversation.users }
|
|
141
141
|
end
|
|
142
142
|
```
|
|
143
143
|
|
|
@@ -162,10 +162,10 @@ You can combine multiple `syncs_to_dexie` declarations, each with different cond
|
|
|
162
162
|
|
|
163
163
|
```ruby
|
|
164
164
|
class Message < ApplicationRecord
|
|
165
|
-
|
|
165
|
+
syncs_to_dexie via: UserChannel, subject: -> { sender },
|
|
166
166
|
if: :published?
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
syncs_to_dexie via: AdminChannel,
|
|
169
169
|
unless: -> { draft? }
|
|
170
170
|
end
|
|
171
171
|
```
|
|
@@ -176,7 +176,7 @@ Override `as_json_for_dexie` in your model:
|
|
|
176
176
|
|
|
177
177
|
```ruby
|
|
178
178
|
class Message < ApplicationRecord
|
|
179
|
-
|
|
179
|
+
syncs_to_dexie via: UserChannel, subject: :sender
|
|
180
180
|
|
|
181
181
|
def as_json_for_dexie
|
|
182
182
|
super.merge(room_name: room.name)
|
|
@@ -9,10 +9,10 @@ module DexieCable
|
|
|
9
9
|
# DexieCable channel.
|
|
10
10
|
#
|
|
11
11
|
# class Message < ApplicationRecord
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
12
|
+
# syncs_to_dexie via: UserChannel, subject: :sender
|
|
13
|
+
# syncs_to_dexie via: UserChannel, subject: "global_feed"
|
|
14
|
+
# syncs_to_dexie via: UserChannel, subject: -> { conversation.users }
|
|
15
|
+
# syncs_to_dexie via: PublicChannel
|
|
16
16
|
# end
|
|
17
17
|
#
|
|
18
18
|
# @param via [Class] A DexieCable channel class. When +subject+
|
data/lib/dexiecable/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dexiecable
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stefan Buhrmester
|
|
@@ -39,7 +39,7 @@ dependencies:
|
|
|
39
39
|
version: '7.0'
|
|
40
40
|
description: DexieCable augments ActionCable channels with a query DSL that mirrors
|
|
41
41
|
the Dexie.js API, letting you push database mutations from the server to the client
|
|
42
|
-
in real time. Includes an ActiveRecord macro (
|
|
42
|
+
in real time. Includes an ActiveRecord macro (syncs_to_dexie) for automatic change
|
|
43
43
|
syncing.
|
|
44
44
|
email:
|
|
45
45
|
- stefan@buhrmi.de
|