hyper-mesh 0.5.3 → 0.5.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.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Gemfile +7 -2
- data/README.md +112 -87
- data/Rakefile +6 -1
- data/docs/action_cable_quickstart.md +20 -16
- data/docs/activerecord_api.md +23 -17
- data/docs/authorization-policies.md +45 -35
- data/docs/client_side_scoping.md +5 -5
- data/docs/configuration_details.md +6 -46
- data/docs/pusher_faker_quickstart.md +7 -68
- data/docs/pusher_quickstart.md +7 -68
- data/docs/simple_poller_quickstart.md +6 -67
- data/docs/todo-example.md +2 -2
- data/docs/word_game.md +3 -1
- data/docs/words-example.md +2 -3
- data/examples/action-cable/Gemfile +2 -1
- data/examples/action-cable/Gemfile.lock +73 -54
- data/examples/action-cable/config/initializers/{hyper_mesh.rb → hyperloop.rb} +1 -1
- data/examples/action-cable/config/routes.rb +1 -1
- data/hyper-mesh.gemspec +10 -4
- data/lib/active_record_base.rb +3 -3
- data/{examples/action-cable-production-mode/log/.keep → lib/acts_as_string.rb} +0 -0
- data/lib/hyper-mesh.rb +11 -19
- data/lib/hyper_mesh/version.rb +3 -0
- data/lib/hypermesh/version.rb +1 -1
- data/lib/reactive_record/active_record/class_methods.rb +10 -3
- data/lib/reactive_record/active_record/instance_methods.rb +8 -0
- data/lib/reactive_record/active_record/public_columns_hash.rb +8 -2
- data/lib/reactive_record/active_record/reactive_record/collection.rb +0 -1
- data/lib/reactive_record/active_record/reactive_record/dummy_value.rb +2 -1
- data/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb +55 -63
- data/lib/reactive_record/active_record/reactive_record/operations.rb +51 -0
- data/lib/reactive_record/active_record/reactive_record/reactive_set_relationship_helpers.rb +3 -3
- data/lib/reactive_record/active_record/reactive_record/while_loading.rb +93 -84
- data/lib/reactive_record/broadcast.rb +183 -0
- data/lib/reactive_record/permissions.rb +2 -2
- data/reactive_record_test_app/Gemfile +6 -2
- data/reactive_record_test_app/Gemfile.lock +120 -60
- data/reactive_record_test_app/app/assets/javascripts/application.rb +3 -5
- data/reactive_record_test_app/app/assets/javascripts/bigdecimal.rb +1 -0
- data/reactive_record_test_app/app/assets/javascripts/reactive_record_config.js +2 -2
- data/reactive_record_test_app/app/controllers/application_controller.rb +3 -3
- data/reactive_record_test_app/app/controllers/home_controller.rb +1 -1
- data/reactive_record_test_app/app/models/models.rb.erb +6 -0
- data/reactive_record_test_app/config/application.rb +2 -0
- data/reactive_record_test_app/config/environments/development.rb +1 -1
- data/reactive_record_test_app/config/routes.rb +1 -2
- data/reactive_record_test_app/db/seeds.rb +6 -0
- data/reactive_record_test_app/script/rails +0 -0
- data/reactive_record_test_app/spec-opal/active-record/rendering_spec.rb +11 -2
- data/reactive_record_test_app/spec-opal/active-record/save_spec.rb +3 -4
- data/reactive_record_test_app/spec-opal/spec_helper.js.rb +1 -1
- data/reactive_record_test_app/spec-opal/test_spec.rb +7 -0
- data/reactive_record_test_app/spec_dont_run/README.md +7 -0
- data/reactive_record_test_app/{spec-opal/active-record → spec_dont_run/active_record_broken}/permissions_spec.rb +0 -0
- data/reactive_record_test_app/{spec-opal/active-record → spec_dont_run/active_record_broken}/prerendering_spec.rb +1 -0
- data/spec/{synchromesh/aaa-unit_tests/connection_spec.rb → batch1/aaa-unit_tests/connection_movedspec.rb} +0 -0
- data/spec/{synchromesh → batch1}/aaa-unit_tests/dummy_value_spec.rb +2 -2
- data/spec/{synchromesh → batch1}/column_types/column_type_spec.rb +2 -2
- data/spec/{synchromesh → batch1}/crud_access_regulation/broadcast_controls_access_spec.rb +1 -1
- data/spec/{synchromesh → batch1}/crud_access_regulation/model_policies_spec.rb +6 -6
- data/spec/batch1/misc/access_like_hash_spec.rb +43 -0
- data/spec/batch1/misc/while_loading_spec.rb +196 -0
- data/spec/{synchromesh → batch1}/policies/regulate_all_broadcasts_spec.rb +12 -12
- data/spec/{synchromesh → batch1}/policies/regulate_broadcast_spec.rb +25 -25
- data/spec/{synchromesh/integration → batch2}/authorization_spec.rb +8 -7
- data/spec/{synchromesh/integration → batch2}/default_scope_spec.rb +2 -2
- data/spec/{synchromesh/integration → batch2}/has_many_through_spec.rb +2 -2
- data/spec/{synchromesh/integration → batch2}/relationships_spec.rb +3 -3
- data/spec/{reactive_record → batch3}/auto_load_itself_spec.rb +1 -1
- data/spec/{reactive_record → batch3}/edge_cases_spec.rb +1 -1
- data/spec/{reactive_record → batch3}/finder_method_spec.rb +1 -1
- data/spec/{reactive_record → batch3}/many_to_many_spec.rb +2 -2
- data/spec/{reactive_record → batch3}/pry_rescue_xspec.rb +0 -0
- data/{examples/action-cable-production-mode/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css → spec/batch3/readme.txt} +0 -0
- data/spec/{reactive_record → batch3}/revert_spec.rb +2 -2
- data/spec/{reactive_record → batch3}/save_while_loading_spec.rb +1 -1
- data/spec/{reactive_record → batch3}/update_associations_spec.rb +2 -2
- data/spec/{reactive_record → batch3}/update_scopes_spec.rb +2 -2
- data/spec/{synchromesh/integration → batch4}/saving_during_commit_spec.rb +2 -2
- data/spec/{synchromesh/integration → batch4}/scope_spec.rb +30 -2
- data/spec/{synchromesh/examples → batch4}/scoped_todos_spec.rb +3 -3
- data/spec/{synchromesh/integration → batch4}/synchromesh_spec.rb +2 -2
- data/spec/{synchromesh/examples → examples}/dictionary.rb +2 -2
- data/spec/{synchromesh/examples → examples}/dictionary_with_client_scopes.rb +2 -2
- data/spec/{synchromesh/examples → examples}/random_examples.rb +1 -1
- data/spec/{reactive_record/play.rb → play_ground.rb} +0 -0
- data/spec/{reactive_record/factory.rb → reactive_record_factory.rb} +0 -0
- data/spec/spec_helper.rb +3 -2
- data/spec/test_app/Gemfile +8 -3
- data/spec/test_app/Gemfile.lock +114 -64
- data/spec/test_app/app/views/components.rb +1 -2
- data/spec/test_app/config/application.rb +2 -0
- data/spec/test_app/config/routes.rb +1 -1
- data/spec/{synchromesh/integration/test_components.rb → test_components.rb} +0 -0
- metadata +144 -137
- data/app/controllers/reactive_record/application_controller.rb +0 -4
- data/app/controllers/reactive_record/reactive_record_controller.rb +0 -49
- data/config/routes.rb +0 -7
- data/examples/action-cable-production-mode/public/assets/application-90043e04e9e784054fd08159fa7aafe5e23d3ffb31584b1bea1e47043c9cfb5a.js +0 -50
- data/examples/action-cable-production-mode/public/assets/application-90043e04e9e784054fd08159fa7aafe5e23d3ffb31584b1bea1e47043c9cfb5a.js.gz +0 -0
- data/examples/action-cable-production-mode/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css.gz +0 -0
- data/examples/action-cable-production-mode/tmp/.keep +0 -0
- data/examples/action-cable/log/.keep +0 -0
- data/examples/action-cable/tmp/.keep +0 -0
- data/examples/pusher-fake/log/.keep +0 -0
- data/examples/pusher-fake/tmp/.keep +0 -0
- data/examples/pusher/log/.keep +0 -0
- data/examples/pusher/tmp/.keep +0 -0
- data/examples/simple-poller/log/.keep +0 -0
- data/examples/simple-poller/tmp/.keep +0 -0
- data/examples/word-game/log/.keep +0 -0
- data/examples/word-game/tmp/.keep +0 -0
- data/examples/words/log/.keep +0 -0
- data/examples/words/tmp/.keep +0 -0
- data/lib/reactive_record/version.rb +0 -3
- data/lib/sources/hyper-mesh/pusher.js +0 -98
- data/lib/synchromesh/action_cable.rb +0 -39
- data/lib/synchromesh/client_drivers.rb +0 -357
- data/lib/synchromesh/configuration.rb +0 -40
- data/lib/synchromesh/connection.rb +0 -170
- data/lib/synchromesh/policy.rb +0 -504
- data/lib/synchromesh/synchromesh.rb +0 -159
- data/lib/synchromesh/synchromesh_controller.rb +0 -162
- data/reactive_record_test_app/README.rdoc +0 -261
- data/reactive_record_test_app/app/assets/javascripts/components/another_component.rb +0 -24
- data/reactive_record_test_app/app/assets/javascripts/components/empty_component.rb +0 -6
- data/reactive_record_test_app/app/assets/javascripts/components/todo_item_component.js.rb +0 -16
- data/reactive_record_test_app/app/assets/javascripts/components/todos_component.js.rb +0 -42
- data/reactive_record_test_app/app/assets/javascripts/components/todos_main_component.rb +0 -49
- data/reactive_record_test_app/app/assets/javascripts/react_js_test_only.js +0 -21618
- data/reactive_record_test_app/app/assets/javascripts/spec/reactive_record_xspec.js.rb +0 -42
- data/reactive_record_test_app/app/controllers/test_controller.rb +0 -7
- data/reactive_record_test_app/app/mailers/.gitkeep +0 -0
- data/reactive_record_test_app/app/models/models.rb +0 -1
- data/reactive_record_test_app/app/policies/application_policy.rb +0 -5
- data/reactive_record_test_app/app/views/components.rb +0 -4
- data/reactive_record_test_app/app/views/components/test.rb +0 -18
- data/reactive_record_test_app/app/views/home/index.html.erb +0 -1
- data/reactive_record_test_app/app/views/layouts/application.html.erb +0 -17
- data/reactive_record_test_app/config/environments/production.rb +0 -70
- data/reactive_record_test_app/config/environments/test.rb +0 -41
- data/spec/synchromesh/integration/transports_spec.rb +0 -308
- data/spec/synchromesh/policies/auto_connect_spec.rb +0 -60
- data/spec/synchromesh/policies/auto_loader_spec.rb +0 -34
- data/spec/synchromesh/policies/policy_methods_spec.rb +0 -85
- data/spec/synchromesh/policies/regulate_class_connection_spec.rb +0 -50
- data/spec/synchromesh/policies/regulate_instance_connection_spec.rb +0 -66
- data/spec/test_app/log/.keep +0 -0
data/hyper-mesh.gemspec
CHANGED
|
@@ -23,8 +23,10 @@ Gem::Specification.new do |s|
|
|
|
23
23
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
|
24
24
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
25
25
|
s.require_paths = ['lib']
|
|
26
|
+
|
|
26
27
|
s.add_dependency 'activerecord', '>= 0.3.0'
|
|
27
|
-
s.add_dependency 'hyper-
|
|
28
|
+
s.add_dependency 'hyper-operation', '>= 0.5.0'
|
|
29
|
+
s.add_dependency 'hyper-component', '>= 0.12.3'
|
|
28
30
|
|
|
29
31
|
s.add_development_dependency 'bundler', '~> 1.8'
|
|
30
32
|
s.add_development_dependency 'rake', '~> 10.0'
|
|
@@ -39,12 +41,15 @@ Gem::Specification.new do |s|
|
|
|
39
41
|
s.add_development_dependency 'factory_girl_rails'
|
|
40
42
|
s.add_development_dependency 'reactrb-rails-generator'
|
|
41
43
|
s.add_development_dependency 'rspec-wait'
|
|
42
|
-
s.add_development_dependency 'puma'
|
|
44
|
+
s.add_development_dependency 'puma', '~> 3.6.0'
|
|
43
45
|
|
|
44
46
|
s.add_development_dependency 'pusher'
|
|
45
47
|
s.add_development_dependency 'pusher-fake'
|
|
46
48
|
s.add_development_dependency 'opal-browser'
|
|
47
49
|
|
|
50
|
+
# Keep linter-rubocop happy
|
|
51
|
+
s.add_development_dependency 'rubocop'
|
|
52
|
+
|
|
48
53
|
if RUBY_PLATFORM == 'java'
|
|
49
54
|
s.add_development_dependency 'jdbc-sqlite3'
|
|
50
55
|
s.add_development_dependency 'activerecord-jdbcsqlite3-adapter'
|
|
@@ -68,7 +73,7 @@ Gem::Specification.new do |s|
|
|
|
68
73
|
s.add_development_dependency 'rspec-collection_matchers'
|
|
69
74
|
s.add_development_dependency 'database_cleaner'
|
|
70
75
|
s.add_development_dependency 'capybara'
|
|
71
|
-
s.add_development_dependency 'selenium-webdriver'
|
|
76
|
+
s.add_development_dependency 'selenium-webdriver', '< 3'
|
|
72
77
|
s.add_development_dependency 'poltergeist'
|
|
73
78
|
s.add_development_dependency 'spring-commands-rspec'
|
|
74
79
|
s.add_development_dependency 'chromedriver-helper'
|
|
@@ -77,6 +82,7 @@ Gem::Specification.new do |s|
|
|
|
77
82
|
s.add_development_dependency 'unparser'
|
|
78
83
|
s.add_development_dependency 'jquery-rails'
|
|
79
84
|
s.add_development_dependency 'pry-byebug'
|
|
80
|
-
|
|
85
|
+
s.add_development_dependency 'hyper-spec'
|
|
86
|
+
s.add_development_dependency 'hyper-trace'
|
|
81
87
|
end
|
|
82
88
|
end
|
data/lib/active_record_base.rb
CHANGED
|
@@ -137,17 +137,17 @@ module ActiveRecord
|
|
|
137
137
|
|
|
138
138
|
def synchromesh_after_create
|
|
139
139
|
return if do_not_synchronize? #|| previous_changes.empty?
|
|
140
|
-
|
|
140
|
+
ReactiveRecord::Broadcast.after_commit :create, self
|
|
141
141
|
end
|
|
142
142
|
|
|
143
143
|
def synchromesh_after_change
|
|
144
144
|
return if do_not_synchronize? || previous_changes.empty?
|
|
145
|
-
|
|
145
|
+
ReactiveRecord::Broadcast.after_commit :change, self
|
|
146
146
|
end
|
|
147
147
|
|
|
148
148
|
def synchromesh_after_destroy
|
|
149
149
|
return if do_not_synchronize?
|
|
150
|
-
|
|
150
|
+
ReactiveRecord::Broadcast.after_commit :destroy, self
|
|
151
151
|
end
|
|
152
152
|
else
|
|
153
153
|
|
|
File without changes
|
data/lib/hyper-mesh.rb
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
# module ApplicationCable
|
|
2
|
-
# class Connection < ActionCable::Connection::Base
|
|
3
|
-
# # we always create a connection, and use the session_id to identify it.
|
|
4
|
-
# #identified_by :session
|
|
5
|
-
#
|
|
6
|
-
# # def connect
|
|
7
|
-
# # #self.session = cookies.encrypted[Rails.application.config.session_options[:key]]
|
|
8
|
-
# # end
|
|
9
|
-
# end
|
|
10
|
-
# end
|
|
11
|
-
|
|
12
1
|
require 'set'
|
|
2
|
+
require 'hyperloop-config'
|
|
3
|
+
require 'hyper-component'
|
|
13
4
|
if RUBY_ENGINE == 'opal'
|
|
14
|
-
require
|
|
5
|
+
require 'hyper-operation'
|
|
15
6
|
require 'active_support'
|
|
16
7
|
require 'time'
|
|
17
8
|
require 'date'
|
|
@@ -19,6 +10,8 @@ if RUBY_ENGINE == 'opal'
|
|
|
19
10
|
require "reactive_record/active_record/error"
|
|
20
11
|
require "reactive_record/server_data_cache"
|
|
21
12
|
require "reactive_record/active_record/reactive_record/while_loading"
|
|
13
|
+
require "reactive_record/active_record/reactive_record/operations"
|
|
14
|
+
require 'reactive_record/broadcast'
|
|
22
15
|
require "reactive_record/active_record/reactive_record/isomorphic_base"
|
|
23
16
|
require 'reactive_record/active_record/reactive_record/dummy_value'
|
|
24
17
|
require 'reactive_record/active_record/reactive_record/column_types'
|
|
@@ -39,26 +32,25 @@ if RUBY_ENGINE == 'opal'
|
|
|
39
32
|
require_relative 'opal/parse_patch'
|
|
40
33
|
require_relative 'opal/set_patches'
|
|
41
34
|
require_relative 'opal/equality_patches'
|
|
35
|
+
React::IsomorphicHelpers.log(
|
|
36
|
+
"The gem 'hyper-mesh' is deprecated. Use gem 'hyper-model' instead.", :warning
|
|
37
|
+
) unless defined? Hyperloop::Model
|
|
42
38
|
else
|
|
43
39
|
require 'opal'
|
|
44
|
-
require 'hyper-
|
|
40
|
+
require 'hyper-operation'
|
|
45
41
|
require "reactive_record/permissions"
|
|
46
|
-
require "reactive_record/engine"
|
|
47
42
|
require "reactive_record/server_data_cache"
|
|
43
|
+
require "reactive_record/active_record/reactive_record/operations"
|
|
44
|
+
require 'reactive_record/broadcast'
|
|
48
45
|
require "reactive_record/active_record/reactive_record/isomorphic_base"
|
|
49
46
|
require "reactive_record/active_record/public_columns_hash"
|
|
50
47
|
require "reactive_record/serializers"
|
|
51
48
|
require "reactive_record/pry"
|
|
52
49
|
require_relative 'active_record_base'
|
|
53
50
|
require 'hypermesh/version'
|
|
54
|
-
require 'synchromesh/connection'
|
|
55
|
-
require 'synchromesh/synchromesh'
|
|
56
|
-
require 'synchromesh/policy'
|
|
57
|
-
require 'synchromesh/synchromesh_controller'
|
|
58
51
|
|
|
59
52
|
Opal.append_path File.expand_path('../sources/', __FILE__).untaint
|
|
60
53
|
Opal.append_path File.expand_path('../', __FILE__).untaint
|
|
61
54
|
Opal.append_path File.expand_path('../../vendor', __FILE__).untaint
|
|
62
55
|
end
|
|
63
56
|
require 'enumerable/pluck'
|
|
64
|
-
require_relative 'synchromesh/client_drivers'
|
data/lib/hypermesh/version.rb
CHANGED
|
@@ -135,7 +135,7 @@ module ActiveRecord
|
|
|
135
135
|
:distinct, :unscope, :calculate, :average, :count_by_sql, :minimum, :lock, :find_by_sql, :count, :cache, :uncached, :connection, :connection_pool,
|
|
136
136
|
:establish_connection, :connected?, :clear_cache!, :clear_reloadable_connections!, :connection_id, :connection_config, :clear_all_connections!,
|
|
137
137
|
:remove_connection, :connection_specification_name, :connection_specification_name=, :retrieve_connection, :connection_id=, :clear_active_connections!,
|
|
138
|
-
:sqlite3_connection, :direct_descendants, :benchmark, :model_name
|
|
138
|
+
:sqlite3_connection, :direct_descendants, :benchmark, :model_name, :with_options, :attr_protected, :attr_accessible
|
|
139
139
|
]
|
|
140
140
|
|
|
141
141
|
def method_missing(name, *args, &block)
|
|
@@ -210,11 +210,11 @@ module ActiveRecord
|
|
|
210
210
|
end
|
|
211
211
|
|
|
212
212
|
def column_names
|
|
213
|
-
|
|
213
|
+
ReactiveRecord::Base.public_columns_hash.keys
|
|
214
214
|
end
|
|
215
215
|
|
|
216
216
|
def columns_hash
|
|
217
|
-
|
|
217
|
+
ReactiveRecord::Base.public_columns_hash[name] || {}
|
|
218
218
|
end
|
|
219
219
|
|
|
220
220
|
def server_methods
|
|
@@ -275,6 +275,13 @@ module ActiveRecord
|
|
|
275
275
|
[key, [value]]
|
|
276
276
|
end
|
|
277
277
|
end
|
|
278
|
+
|
|
279
|
+
# We do want to be doing something like this, but this breaks other stuff...
|
|
280
|
+
#
|
|
281
|
+
# ReactiveRecord::Base.load_data do
|
|
282
|
+
# ReactiveRecord::ServerDataCache.load_from_json(Hash[param], target)
|
|
283
|
+
# end
|
|
284
|
+
|
|
278
285
|
ReactiveRecord::ServerDataCache.load_from_json(Hash[param], target)
|
|
279
286
|
target
|
|
280
287
|
end
|
|
@@ -73,6 +73,14 @@ module ActiveRecord
|
|
|
73
73
|
@backing_record == ar_instance.instance_eval { @backing_record }
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
+
def [](attr)
|
|
77
|
+
send(attr)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def []=(attr, val)
|
|
81
|
+
send("#{attr}=", val)
|
|
82
|
+
end
|
|
83
|
+
|
|
76
84
|
def method_missing_warning(name)
|
|
77
85
|
@backing_record.deprecation_warning("Server side method #{name} must be defined using the 'server_method' macro.")
|
|
78
86
|
end
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
module Hyperloop
|
|
2
|
+
define_setting :public_model_directories, ['app/models/public', 'app/hyperloop/models']
|
|
3
|
+
end
|
|
4
|
+
|
|
1
5
|
module ActiveRecord
|
|
2
6
|
# adds method to get the HyperMesh public column types
|
|
3
7
|
# for now we are just getting all models column types, but we should
|
|
@@ -6,8 +10,10 @@ module ActiveRecord
|
|
|
6
10
|
class Base
|
|
7
11
|
def self.public_columns_hash
|
|
8
12
|
return @public_columns_hash if @public_columns_hash
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
Hyperloop.public_model_directories.each do |dir|
|
|
14
|
+
Dir.glob(Rails.root.join("#{dir}/*.rb")).each do |file|
|
|
15
|
+
require_dependency(file)
|
|
16
|
+
end
|
|
11
17
|
end
|
|
12
18
|
@public_columns_hash = {}
|
|
13
19
|
descendants.each do |model|
|
|
@@ -483,7 +483,6 @@ module ReactiveRecord
|
|
|
483
483
|
elsif ScopeDescription.find(@target_klass, method) || (args.count == 1 && method =~ /^find_by_/)
|
|
484
484
|
apply_scope(method, *args)
|
|
485
485
|
elsif @target_klass.respond_to?(method) && ScopeDescription.find(@target_klass, "_#{method}")
|
|
486
|
-
puts "here we are..."
|
|
487
486
|
apply_scope("_#{method}", *args).first
|
|
488
487
|
else
|
|
489
488
|
super
|
|
@@ -7,10 +7,11 @@ module ReactiveRecord
|
|
|
7
7
|
include React::IsomorphicHelpers
|
|
8
8
|
|
|
9
9
|
before_first_mount do |context|
|
|
10
|
-
HyperMesh::ClientDrivers.on_first_mount
|
|
11
10
|
if RUBY_ENGINE != 'opal'
|
|
12
11
|
@server_data_cache = ReactiveRecord::ServerDataCache.new(context.controller.acting_user, {})
|
|
13
12
|
else
|
|
13
|
+
@public_columns_hash = get_public_columns_hash
|
|
14
|
+
define_attribute_methods
|
|
14
15
|
@outer_scopes = Set.new
|
|
15
16
|
@fetch_scheduled = nil
|
|
16
17
|
@records = Hash.new { |hash, key| hash[key] = [] }
|
|
@@ -60,6 +61,22 @@ module ReactiveRecord
|
|
|
60
61
|
f.when_on_server { @server_data_cache[klass, ["find_by_#{attribute}", value], :id] }
|
|
61
62
|
end
|
|
62
63
|
|
|
64
|
+
class << self
|
|
65
|
+
attr_reader :public_columns_hash
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def self.define_attribute_methods
|
|
69
|
+
public_columns_hash.keys.each do |model|
|
|
70
|
+
Object.const_get(model).define_attribute_methods rescue nil
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
isomorphic_method(:get_public_columns_hash) do |f|
|
|
75
|
+
f.when_on_client { JSON.parse(`JSON.stringify(window.ReactiveRecordPublicColumnsHash)`) }
|
|
76
|
+
f.send_to_server
|
|
77
|
+
f.when_on_server { ActiveRecord::Base.public_columns_hash }
|
|
78
|
+
end
|
|
79
|
+
|
|
63
80
|
prerender_footer do
|
|
64
81
|
if @server_data_cache
|
|
65
82
|
json = @server_data_cache.as_json.to_json # can this just be to_json?
|
|
@@ -67,12 +84,9 @@ module ReactiveRecord
|
|
|
67
84
|
else
|
|
68
85
|
json = {}.to_json
|
|
69
86
|
end
|
|
70
|
-
path = ::Rails.application.routes.routes.detect do |route|
|
|
71
|
-
# not sure why the second check is needed. It happens in the test app
|
|
72
|
-
route.app == HyperMesh::Engine or (route.app.respond_to?(:app) and route.app.app == HyperMesh::Engine)
|
|
73
|
-
end.path.spec
|
|
74
87
|
"<script type='text/javascript'>\n"+
|
|
75
|
-
"window.
|
|
88
|
+
"if (typeof window.ReactiveRecordPublicColumnsHash === 'undefined') { \n" +
|
|
89
|
+
" window.ReactiveRecordPublicColumnsHash = #{ActiveRecord::Base.public_columns_hash.to_json}}\n" +
|
|
76
90
|
"if (typeof window.ReactiveRecordInitialData === 'undefined') { window.ReactiveRecordInitialData = [] }\n" +
|
|
77
91
|
"window.ReactiveRecordInitialData.push(#{json})\n"+
|
|
78
92
|
"</script>\n"
|
|
@@ -127,31 +141,26 @@ module ReactiveRecord
|
|
|
127
141
|
models, associations = gather_records(@pending_records, false, nil)
|
|
128
142
|
log(["Server Fetching: %o", pending_fetches.to_n])
|
|
129
143
|
start_time = Time.now
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
ReactiveRecord::
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
Operations::Fetch(models: models, associations: associations, pending_fetches: pending_fetches)
|
|
145
|
+
.then do |response|
|
|
146
|
+
fetch_time = Time.now
|
|
147
|
+
log(" Fetched in: #{(fetch_time-start_time).to_i}s")
|
|
148
|
+
begin
|
|
149
|
+
ReactiveRecord::Base.load_from_json(response)
|
|
150
|
+
rescue Exception => e
|
|
151
|
+
log("Unexpected exception raised while loading json from server: #{e}", :error)
|
|
152
|
+
end
|
|
153
|
+
log(" Processed in: #{(Time.now-fetch_time).to_i}s")
|
|
154
|
+
log([" Returned: %o", response.to_n])
|
|
155
|
+
ReactiveRecord.run_blocks_to_load last_fetch_at
|
|
156
|
+
ReactiveRecord::WhileLoading.loaded_at last_fetch_at
|
|
157
|
+
ReactiveRecord::WhileLoading.quiet! if @pending_fetches.empty?
|
|
158
|
+
end
|
|
159
|
+
.fail do |response|
|
|
160
|
+
log("Fetch failed", :error)
|
|
161
|
+
# not sure what response was supposed to look like here was response.body before conversion to operations....
|
|
162
|
+
ReactiveRecord.run_blocks_to_load(last_fetch_at, response)
|
|
145
163
|
end
|
|
146
|
-
log(" Processed in: #{(Time.now-fetch_time).to_i}s")
|
|
147
|
-
log([" Returned: %o", response.json.to_n])
|
|
148
|
-
ReactiveRecord.run_blocks_to_load last_fetch_at
|
|
149
|
-
ReactiveRecord::WhileLoading.loaded_at last_fetch_at
|
|
150
|
-
ReactiveRecord::WhileLoading.quiet! if @pending_fetches.empty?
|
|
151
|
-
end.fail do |response|
|
|
152
|
-
log("Fetch failed", :error)
|
|
153
|
-
ReactiveRecord.run_blocks_to_load(last_fetch_at, response.body)
|
|
154
|
-
end
|
|
155
164
|
@pending_fetches = []
|
|
156
165
|
@pending_records = []
|
|
157
166
|
@fetch_scheduled = nil
|
|
@@ -247,40 +256,31 @@ module ReactiveRecord
|
|
|
247
256
|
backing_records.each { |id, record| record.saving! }
|
|
248
257
|
|
|
249
258
|
promise = Promise.new
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
payload: {
|
|
253
|
-
json: {
|
|
254
|
-
models: models,
|
|
255
|
-
associations: associations,
|
|
256
|
-
validate: validate
|
|
257
|
-
}.to_json
|
|
258
|
-
}
|
|
259
|
-
).then do |response|
|
|
259
|
+
Operations::Save(models: models, associations: associations, validate: validate)
|
|
260
|
+
.then do |response|
|
|
260
261
|
begin
|
|
261
|
-
response
|
|
262
|
+
response[:models] = response[:saved_models].collect do |item|
|
|
262
263
|
backing_records[item[0]].ar_instance
|
|
263
264
|
end
|
|
264
265
|
|
|
265
|
-
if response
|
|
266
|
-
response
|
|
267
|
-
|
|
268
|
-
HyperMesh::LocalSync.after_save backing_records[item[0]].ar_instance, item[2]
|
|
266
|
+
if response[:success]
|
|
267
|
+
response[:saved_models].each do | item |
|
|
268
|
+
Broadcast.to_self backing_records[item[0]].ar_instance, item[2]
|
|
269
269
|
end
|
|
270
270
|
else
|
|
271
|
-
log("Reactive Record Save Failed: #{response
|
|
272
|
-
response
|
|
271
|
+
log("Reactive Record Save Failed: #{response[:message]}", :error)
|
|
272
|
+
response[:saved_models].each do | item |
|
|
273
273
|
log(" Model: #{item[1]}[#{item[0]}] Attributes: #{item[2]} Errors: #{item[3]}", :error) if item[3]
|
|
274
274
|
end
|
|
275
275
|
end
|
|
276
276
|
|
|
277
|
-
response
|
|
277
|
+
response[:saved_models].each do | item |
|
|
278
278
|
backing_records[item[0]].sync_unscoped_collection!
|
|
279
279
|
backing_records[item[0]].errors! item[3]
|
|
280
280
|
end
|
|
281
281
|
|
|
282
|
-
yield response
|
|
283
|
-
promise.resolve response.json
|
|
282
|
+
yield response[:success], response[:message], response[:models] if block
|
|
283
|
+
promise.resolve response # TODO this could be problematic... there was no .json here, so .... what's to do?
|
|
284
284
|
|
|
285
285
|
backing_records.each { |id, record| record.saved! }
|
|
286
286
|
|
|
@@ -496,19 +496,11 @@ module ReactiveRecord
|
|
|
496
496
|
promise = Promise.new
|
|
497
497
|
|
|
498
498
|
if !data_loading? and (id or vector)
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
vector: vector
|
|
505
|
-
}.to_json
|
|
506
|
-
}
|
|
507
|
-
).then do |response|
|
|
508
|
-
#sync_unscoped_collection!
|
|
509
|
-
HyperMesh::LocalSync.after_save ar_instance
|
|
510
|
-
yield response.json[:success], response.json[:message] if block
|
|
511
|
-
promise.resolve response.json
|
|
499
|
+
Operations::Destroy(model: ar_instance.model_name, id: id, vector: vector)
|
|
500
|
+
.then do |response|
|
|
501
|
+
Broadcast.to_self ar_instance
|
|
502
|
+
yield response[:success], response[:message] if block
|
|
503
|
+
promise.resolve response
|
|
512
504
|
end
|
|
513
505
|
else
|
|
514
506
|
destroy_associations
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module ReactiveRecord
|
|
2
|
+
module Operations
|
|
3
|
+
# fetch queued up records from the server
|
|
4
|
+
class Fetch < Hyperloop::ServerOp
|
|
5
|
+
param :acting_user, nils: true
|
|
6
|
+
param models: []
|
|
7
|
+
param associations: []
|
|
8
|
+
param :pending_fetches
|
|
9
|
+
step do
|
|
10
|
+
ReactiveRecord::ServerDataCache[
|
|
11
|
+
params.models.map(&:with_indifferent_access),
|
|
12
|
+
params.associations.map(&:with_indifferent_access),
|
|
13
|
+
params.pending_fetches,
|
|
14
|
+
params.acting_user
|
|
15
|
+
]
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class Save < Hyperloop::ServerOp
|
|
20
|
+
param :acting_user, nils: true
|
|
21
|
+
param models: []
|
|
22
|
+
param associations: []
|
|
23
|
+
param :validate, type: :boolean
|
|
24
|
+
|
|
25
|
+
step do
|
|
26
|
+
ReactiveRecord::Base.save_records(
|
|
27
|
+
params.models.map(&:with_indifferent_access),
|
|
28
|
+
params.associations.map(&:with_indifferent_access),
|
|
29
|
+
params.acting_user,
|
|
30
|
+
params.validate,
|
|
31
|
+
true
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class Destroy < Hyperloop::ServerOp
|
|
37
|
+
param :acting_user, nils: true
|
|
38
|
+
param :model
|
|
39
|
+
param :id
|
|
40
|
+
param :vector
|
|
41
|
+
step do
|
|
42
|
+
ReactiveRecord::Base.destroy_record(
|
|
43
|
+
params.model,
|
|
44
|
+
params.id,
|
|
45
|
+
params.vector,
|
|
46
|
+
params.acting_user
|
|
47
|
+
)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|