dexiecable 0.1.0 → 0.1.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/README.md +2 -2
- data/lib/dexiecable/active_record_ext.rb +16 -8
- data/lib/dexiecable/version.rb +1 -1
- 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: 353c08fde431ac528532ebc11a99911154654988345d6c7fdddb479269a65194
|
|
4
|
+
data.tar.gz: ec8e1ab7b1d4f0ea74cc8da8346337cee2b9f82192de966ccc653aedd5f96a38
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c1fabe1bc7d3aa4f16855ffc9f3d1dff472c0488b8b2959745b02225bd5503c3b9e43ea2cc253bc306c742633b5e85da4400b760072d5776f2e925d66cac0529
|
|
7
|
+
data.tar.gz: 0d3c51e4d95f3848c244a0793cd77c2de817646ebef18c79705a42d2cfb4f5e729bbbbf8de466b1cc9f04e79d3f392a1c096f8968746a0c49077b00dee44d502
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# DexieCable
|
|
2
2
|
|
|
3
|
-
Run Dexie.js IndexedDB operations from your Rails ActionCable channels.
|
|
3
|
+
Run [Dexie.js](https://dexie.org) IndexedDB operations from your Rails ActionCable channels.
|
|
4
4
|
|
|
5
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
|
|
|
@@ -144,7 +144,7 @@ end
|
|
|
144
144
|
| Option | Default | Description |
|
|
145
145
|
|---|---|---|
|
|
146
146
|
| `via:` | *(required)* | Proc (evaluated in record context), channel class, or channel instance |
|
|
147
|
-
| `table:` | model's `table_name` | Override the Dexie table name |
|
|
147
|
+
| `table:` | model's `table_name` | Override the Dexie table name. A Proc is evaluated in the record's context. |
|
|
148
148
|
| `only:` | `[:create, :update, :destroy]` | Limit which events trigger a sync |
|
|
149
149
|
|
|
150
150
|
#### Customizing the synced payload
|
|
@@ -17,16 +17,16 @@ module DexieCable
|
|
|
17
17
|
# @param via [Proc, DexieCable] Proc evaluated in record context,
|
|
18
18
|
# must return a channel (responds to +table+). A channel
|
|
19
19
|
# class/instance can also be passed directly. Skipped if nil.
|
|
20
|
-
# @param table [String, Symbol] Override the Dexie table name
|
|
21
|
-
# (defaults to the model's table_name).
|
|
20
|
+
# @param table [String, Symbol, Proc] Override the Dexie table name
|
|
21
|
+
# (defaults to the model's table_name). A Proc is
|
|
22
|
+
# evaluated in the record's context.
|
|
22
23
|
# @param only [Array<Symbol>] Limit which lifecycle events sync.
|
|
23
24
|
# Default: [:create, :update, :destroy].
|
|
24
25
|
def syncs_to_dexie(via:, table: nil, only: nil)
|
|
25
|
-
|
|
26
|
-
events = Array(only || %i[create update destroy])
|
|
26
|
+
events = Array(only || %i[create update destroy])
|
|
27
27
|
|
|
28
28
|
@dexie_sync_configs ||= []
|
|
29
|
-
@dexie_sync_configs << { via: via, table:
|
|
29
|
+
@dexie_sync_configs << { via: via, table: table, only: events }
|
|
30
30
|
|
|
31
31
|
if events.include?(:destroy)
|
|
32
32
|
before_destroy :dexie_sync_before_destroy
|
|
@@ -34,7 +34,7 @@ module DexieCable
|
|
|
34
34
|
after_commit on: :destroy do
|
|
35
35
|
channel = resolve_channel(via)
|
|
36
36
|
next unless channel
|
|
37
|
-
channel.table(
|
|
37
|
+
channel.table(resolve_table(table)).delete(dexie_destroy_id)
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
@@ -42,7 +42,7 @@ module DexieCable
|
|
|
42
42
|
after_commit on: :create do
|
|
43
43
|
channel = resolve_channel(via)
|
|
44
44
|
next unless channel
|
|
45
|
-
channel.table(
|
|
45
|
+
channel.table(resolve_table(table)).add(as_json_for_dexie)
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
@@ -52,7 +52,7 @@ module DexieCable
|
|
|
52
52
|
next unless channel
|
|
53
53
|
|
|
54
54
|
changes = as_json_for_dexie.slice(*saved_changes.keys)
|
|
55
|
-
channel.table(
|
|
55
|
+
channel.table(resolve_table(table)).update(id, changes)
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
end
|
|
@@ -67,6 +67,14 @@ module DexieCable
|
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
+
def resolve_table(table)
|
|
71
|
+
case table
|
|
72
|
+
when Proc then instance_exec(&table).to_s
|
|
73
|
+
when nil then self.class.table_name
|
|
74
|
+
else table.to_s
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
70
78
|
# Override in your model to customise the payload synced to Dexie.
|
|
71
79
|
def as_json_for_dexie
|
|
72
80
|
as_json
|
data/lib/dexiecable/version.rb
CHANGED