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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d2ef7eec5521090e20810959e11933397d67437b
4
- data.tar.gz: a64f0e86c45759b5f6726f525b58bbd6489cd291
2
+ SHA256:
3
+ metadata.gz: a8513d9318e6b82a9afeb358de054c89285c250a68ab6736672ab7bde9f171b0
4
+ data.tar.gz: 2615ddbb4b03e6f8e2134f02d5811e8c174119288ec7797d05c5e9950e3186db
5
5
  SHA512:
6
- metadata.gz: 60bd543d8964f943486b63848b305cb9446da542e4f3ad00ae9feafefab50f35aa7a2fbf48e966d2c62d1d631091544212199b599227e60e504c32542a55a786
7
- data.tar.gz: 2372927f6f20857ccd0c1180b54f88b481e2180d9fddcf496bde61f6bd4e48539921d9addd0d612a2bbe59db6a9a2f7c44632fd6906480c7923adc11ab3678fb
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.text("Test: " + data.value)
135
+ data.element.innerText = "Test: " + data.value
136
136
  } else {
137
- data.element.text(data.value)
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("../spec/dummy/Rakefile", __FILE__)
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,2 +1 @@
1
1
  //= link_directory ../javascripts/model_updates .js
2
- //= link_directory ../stylesheets/model_updates .css
@@ -1,4 +1,4 @@
1
- ModelUpdates.Activator = class Activator {
1
+ ModelUpdates.Activator = class ModelUpdatesActivator {
2
2
  constructor() {
3
3
  ModelUpdates.debug("Activator constructor")
4
4
 
@@ -1,4 +1,4 @@
1
- ModelUpdates.Create = class Create {
1
+ ModelUpdates.Create = class ModelUpdatesCreate {
2
2
  static connect(args) {
3
3
  App.cable.subscriptions.create(
4
4
  {channel: "ModelUpdates::CreateChannel", model: args.model},
@@ -1,4 +1,4 @@
1
- ModelUpdates.Events = class Events {
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
 
@@ -1,4 +1,4 @@
1
- ModelUpdates.Update = class Update {
1
+ ModelUpdates.Update = class ModelUpdatesUpdate {
2
2
  static connect(args) {
3
3
  ModelUpdates.debug("Connecting to update channel for " + JSON.stringify(args.ids))
4
4
 
@@ -6,6 +6,7 @@ class ModelUpdates::CreateChannel < ApplicationCable::Channel
6
6
  stream_from(channel_name, coder: ActiveSupport::JSON) do |data|
7
7
  model = model_class.accessible_by(current_ability).find(data.fetch("id"))
8
8
  next unless model
9
+
9
10
  transmit data
10
11
  end
11
12
  end
@@ -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, ids|
11
- models = model_class_name.safe_constantize.accessible_by(current_ability).where(id: ids).distinct.fix
12
- models.find_each do |model|
13
- stream_model(model: model)
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
@@ -6,6 +6,7 @@ class ModelUpdates::UpdateChannel < ApplicationCable::Channel
6
6
  ids_found = {}
7
7
  models.find_each do |model|
8
8
  next if ids_found.key?(model.id)
9
+
9
10
  ids_found[model.id] = true
10
11
 
11
12
  stream_for model
@@ -5,19 +5,20 @@ module ModelUpdates::ModelExtensions
5
5
 
6
6
  module ClassMethods
7
7
  def model_updates_data
8
- @_model_updates ||= {}
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
- before_save on: :update do
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,
@@ -1,3 +1,3 @@
1
1
  module ModelUpdates
2
- VERSION = "0.0.15".freeze
2
+ VERSION = "0.0.16".freeze
3
3
  end
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.15
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: 2018-06-07 00:00:00.000000000 Z
11
+ date: 2020-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
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: 5.1.0
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: 5.1.0
26
+ version: 0.0.3
27
27
  - !ruby/object:Gem::Dependency
28
- name: active_record_query_fixer
28
+ name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.3
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: 0.0.3
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
- rubyforge_project:
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