model_updates 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +2 -2
- data/Rakefile +1 -1
- data/app/assets/config/model_updates_manifest.js +0 -1
- data/app/assets/javascripts/model_updates/activator.es6 +1 -1
- data/app/assets/javascripts/model_updates/create.es6 +1 -1
- data/app/assets/javascripts/model_updates/events.es6 +10 -5
- data/app/assets/javascripts/model_updates/update.es6 +1 -1
- data/app/channels/model_updates/create_channel.rb +1 -0
- data/app/channels/model_updates/events_channel.rb +8 -6
- data/app/channels/model_updates/update_channel.rb +1 -0
- data/lib/model_updates/model_extensions.rb +4 -3
- data/lib/model_updates/version.rb +1 -1
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a8513d9318e6b82a9afeb358de054c89285c250a68ab6736672ab7bde9f171b0
|
4
|
+
data.tar.gz: 2615ddbb4b03e6f8e2134f02d5811e8c174119288ec7797d05c5e9950e3186db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56505fcff06b39baed766b9edaf30c97c4ca4a06ca75ad68b176747ee9fbc022fa3b6cb02b1df5a435dc390e7e94002cc1c5a2cd8a5ad2ebd5fc04f8e8e491bd
|
7
|
+
data.tar.gz: 22eb70271b4ac53218ea39e0af4307e3454e72134c89f3c12e83cdcc65edc6a557d1109421e306c5fb735a6864d875ae2affc23045787749d8c6f9a5cb1be90f
|
data/README.md
CHANGED
@@ -132,9 +132,9 @@ You can also do a callback, once the value is changed.
|
|
132
132
|
```js
|
133
133
|
function myCallback(data) {
|
134
134
|
if (data.value == "something") {
|
135
|
-
data.element.
|
135
|
+
data.element.innerText = "Test: " + data.value
|
136
136
|
} else {
|
137
|
-
data.element.
|
137
|
+
data.element.innerText = data.value
|
138
138
|
}
|
139
139
|
}
|
140
140
|
```
|
data/Rakefile
CHANGED
@@ -14,7 +14,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
14
14
|
rdoc.rdoc_files.include("lib/**/*.rb")
|
15
15
|
end
|
16
16
|
|
17
|
-
APP_RAKEFILE = File.expand_path("
|
17
|
+
APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
|
18
18
|
load "rails/tasks/engine.rake"
|
19
19
|
load "rails/tasks/statistics.rake"
|
20
20
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
ModelUpdates.Events = class
|
1
|
+
ModelUpdates.Events = class ModelUpdatesEvents {
|
2
2
|
constructor() {
|
3
3
|
this.modelCallbacks = {}
|
4
4
|
this.modelClassCallbacks = {}
|
@@ -10,13 +10,18 @@ ModelUpdates.Events = class Events {
|
|
10
10
|
this.modelCallbacks[args.model] = {}
|
11
11
|
|
12
12
|
if (!this.callbackData["connect_model"][args.model])
|
13
|
-
this.callbackData["connect_model"][args.model] =
|
13
|
+
this.callbackData["connect_model"][args.model] = {}
|
14
14
|
|
15
|
-
if (!this.modelCallbacks[args.model][args.id])
|
15
|
+
if (!this.modelCallbacks[args.model][args.id])
|
16
16
|
this.modelCallbacks[args.model][args.id] = []
|
17
|
-
this.callbackData["connect_model"][args.model].push(args.id)
|
18
|
-
}
|
19
17
|
|
18
|
+
if (!this.callbackData["connect_model"][args.model])
|
19
|
+
this.callbackData["connect_model"][args.model] = {}
|
20
|
+
|
21
|
+
if (!this.callbackData["connect_model"][args.model][args.name])
|
22
|
+
this.callbackData["connect_model"][args.model][args.name] = []
|
23
|
+
|
24
|
+
this.callbackData["connect_model"][args.model][args.name].push(args.id)
|
20
25
|
this.modelCallbacks[args.model][args.id].push(args)
|
21
26
|
}
|
22
27
|
|
@@ -7,10 +7,12 @@ class ModelUpdates::EventsChannel < ApplicationCable::Channel
|
|
7
7
|
private
|
8
8
|
|
9
9
|
def connect_models
|
10
|
-
params[:callback_data][:connect_model].each do |model_class_name,
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
params[:callback_data][:connect_model].each do |model_class_name, events|
|
11
|
+
events.each do |event_name, ids|
|
12
|
+
models = model_class_name.safe_constantize.accessible_by(current_ability).where(id: ids).distinct.fix
|
13
|
+
models.find_each do |model|
|
14
|
+
stream_model(event: event_name, model: model)
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
@@ -21,8 +23,8 @@ private
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
|
-
def stream_model(model:)
|
25
|
-
channel_name = "model_updates_events_model_#{model.class.name}_model_#{model.id}"
|
26
|
+
def stream_model(event:, model:)
|
27
|
+
channel_name = "model_updates_events_model_#{model.class.name}_model_#{model.id}_event_#{event}"
|
26
28
|
stream_from(channel_name, coder: ActiveSupport::JSON) do |data|
|
27
29
|
transmit data
|
28
30
|
end
|
@@ -5,19 +5,20 @@ module ModelUpdates::ModelExtensions
|
|
5
5
|
|
6
6
|
module ClassMethods
|
7
7
|
def model_updates_data
|
8
|
-
@
|
8
|
+
@model_updates_data ||= {}
|
9
9
|
end
|
10
10
|
|
11
11
|
def model_updates_broadcast_attributes(args)
|
12
12
|
model_updates_data[:attributes] = args.fetch(:attributes)
|
13
13
|
|
14
14
|
# Need to remember what changes before callbacks, since it might get changed by gems like AwesomeNestedSet before after_commit is called
|
15
|
-
|
15
|
+
before_update do
|
16
16
|
attribute_changes = {}
|
17
17
|
|
18
18
|
args.fetch(:attributes).each do |attribute_name|
|
19
19
|
method_changed = "saved_changed_to_#{attribute_name}?"
|
20
20
|
next if respond_to?(method_changed) && !__send__(method_changed)
|
21
|
+
|
21
22
|
attribute_changes[attribute_name] = __send__(attribute_name)
|
22
23
|
end
|
23
24
|
|
@@ -87,7 +88,7 @@ module ModelUpdates::ModelExtensions
|
|
87
88
|
|
88
89
|
def model_updates_call(event_name, args = {})
|
89
90
|
ActionCable.server.broadcast(
|
90
|
-
"model_updates_events_model_#{self.class.name}_model_#{id}",
|
91
|
+
"model_updates_events_model_#{self.class.name}_model_#{id}_event_#{event_name}",
|
91
92
|
event_name: event_name,
|
92
93
|
id: id,
|
93
94
|
model: self.class.name,
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: model_updates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaspernj
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: active_record_query_fixer
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.0.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.0.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 5.1.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 5.1.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sprockets-es6
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '0'
|
101
101
|
requirements: []
|
102
|
-
|
103
|
-
rubygems_version: 2.6.13
|
102
|
+
rubygems_version: 3.0.6
|
104
103
|
signing_key:
|
105
104
|
specification_version: 4
|
106
105
|
summary: Rails gem to push updates to models into the frontend through ActionCable
|