Skip to content

Commit ad74ebc

Browse files
committed
Merge branch 'edge' into issue-269
2 parents bc0f0be + c589af1 commit ad74ebc

10 files changed

Lines changed: 79 additions & 26 deletions

File tree

docs/dsl-isomorphic/hyper-model.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ For complete examples with *push* updates, see any of the apps in the `examples`
6464

6565
Depending on the architecture of your application, you may decide that some of your models should be Isomorphic and some should remain server-only. The consideration will be that your Isomorphic models will be compiled by Opal to JavaScript and accessible on he client (without the need for a boilerplate API) - Hyperstack takes care of the communication between your server-side models and their client-side compiled versions and you can use Policy to govern access to the models.
6666

67-
In order for Hyperstack to see your Models (and his make them Isomorphic) you need to move them to the `hyperstack/models` folder. Only models in this folder will be seen by Hyperstack and compiled to Javascript. Once a Model is on this folder it ill be accessable to both your client and server code.
67+
In order for Hyperstack to see your Models (and make them Isomorphic) you need to move them to the `hyperstack/models` folder. Only models in this folder will be seen by Hyperstack and compiled to Javascript. Once a Model is on this folder it ill be accessable to both your client and server code.
6868

6969
| **Location of Models** | **Scope** |
7070
| ------------------------- |---------------|

ruby/hyper-component/hyper-component.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
2323

2424
spec.add_dependency 'hyper-state', Hyperstack::Component::VERSION
2525
spec.add_dependency 'hyperstack-config', Hyperstack::Component::VERSION
26-
spec.add_dependency 'libv8', '~> 6.7.0'
27-
spec.add_dependency 'mini_racer', '~> 0.2.4'
26+
spec.add_dependency 'libv8', '~> 7.3.492.27.1'
27+
spec.add_dependency 'mini_racer', '~> 0.2.6'
2828
spec.add_dependency 'opal', '>= 0.11.0', '< 0.12.0'
2929
spec.add_dependency 'opal-activesupport', '~> 0.3.1'
3030
spec.add_dependency 'react-rails', '>= 2.4.0', '< 2.5.0'

ruby/hyper-model/hyper-model.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Gem::Specification.new do |spec|
3232
spec.add_development_dependency 'bundler', ['>= 1.17.3', '< 2.1']
3333
spec.add_development_dependency 'capybara'
3434
spec.add_development_dependency 'chromedriver-helper', '1.2.0'
35-
spec.add_development_dependency 'libv8'
36-
spec.add_development_dependency 'mini_racer', '~> 0.2.4'
35+
spec.add_development_dependency 'libv8', '~> 7.3.492.27.1'
36+
spec.add_development_dependency 'mini_racer', '~> 0.2.6'
3737
spec.add_development_dependency 'selenium-webdriver'
3838
spec.add_development_dependency 'database_cleaner'
3939
spec.add_development_dependency 'factory_bot_rails'

ruby/hyper-model/lib/reactive_record/active_record/reactive_record/collection.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,22 @@ def empty?
618618
count.zero?
619619
end
620620

621-
def any?
622-
!count.zero?
621+
def any?(*args, &block)
622+
# If there are any args passed in, then the collection is being used in the condition
623+
# and we must load it all into memory.
624+
return all.any?(*args, &block) if args&.length&.positive? || block.present?
625+
626+
# Otherwise we can just check the count for efficiency
627+
!empty?
628+
end
629+
630+
def none?(*args, &block)
631+
# If there are any args passed in, then the collection is being used in the condition
632+
# and we must load it all into memory.
633+
return all.none?(*args, &block) if args&.length&.positive? || block.present?
634+
635+
# Otherwise we can just check the count for efficiency
636+
empty?
623637
end
624638

625639
def method_missing(method, *args, &block)

ruby/hyper-model/spec/batch2/collection_aggregate_methods_spec.rb

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,61 @@
3232
size_window(:small, :portrait)
3333
end
3434

35-
[:count, :empty?, :any?].each do |method|
35+
%i[count empty? any? none?].each do |method|
3636
it "will not retrieve the entire collection when using #{method}" do
3737
FactoryBot.create(:test_model)
3838

39-
expect_promise(<<-RUBY
40-
Hyperstack::Model
41-
.load { TestModel.#{method} }
42-
.then do |val|
43-
if TestModel.all.instance_variable_get('@collection')
44-
"unnecessary fetch of all"
45-
else
46-
val
39+
expect_promise(
40+
<<~RUBY
41+
Hyperstack::Model
42+
.load { TestModel.#{method} }
43+
.then do |val|
44+
if TestModel.all.instance_variable_get('@collection')
45+
"unnecessary fetch of all"
46+
else
47+
val
48+
end
4749
end
48-
end
49-
RUBY
50-
).to eq(TestModel.all.send(method))
50+
RUBY
51+
).to eq(TestModel.all.send(method))
52+
end
53+
end
54+
55+
%i[any? none?].each do |method|
56+
it 'will retrieve the entire collection when using any? if an arg is passed in' do
57+
FactoryBot.create(:test_model)
58+
59+
expect_promise(
60+
<<~RUBY
61+
Hyperstack::Model.load do
62+
TestModel.#{method}(TestModel)
63+
end.then do |val|
64+
if TestModel.all.instance_variable_get('@collection')
65+
'necessary fetch of all'
66+
else
67+
val
68+
end
69+
end
70+
RUBY
71+
).to eq('necessary fetch of all')
72+
end
73+
74+
it 'will retrieve the entire collection when using any? if a block is passed in' do
75+
FactoryBot.create(:test_model)
76+
77+
expect_promise(
78+
<<~RUBY
79+
Hyperstack::Model.load do
80+
TestModel.#{method} { |test_model| test_model }
81+
end.then do |val|
82+
if TestModel.all.instance_variable_get('@collection')
83+
'necessary fetch of all'
84+
else
85+
val
86+
end
87+
end
88+
RUBY
89+
).to eq('necessary fetch of all')
5190
end
5291
end
5392
end

ruby/hyper-router/hyper-router.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
2424
spec.add_development_dependency 'hyper-spec', HyperRouter::VERSION
2525
spec.add_development_dependency 'hyper-store', HyperRouter::VERSION
2626
spec.add_development_dependency 'listen'
27-
spec.add_development_dependency 'mini_racer', '~> 0.2.4'
27+
spec.add_development_dependency 'mini_racer', '~> 0.2.6'
2828
spec.add_development_dependency 'opal-rails', '~> 0.9.4'
2929
spec.add_development_dependency 'parser'
3030
spec.add_development_dependency 'puma'

ruby/hyper-spec/hyper-spec.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
2626

2727
spec.add_dependency 'capybara'
2828
spec.add_dependency 'chromedriver-helper', '1.2.0'
29-
spec.add_dependency 'libv8', '~> 6.7.0'
29+
spec.add_dependency 'libv8', '~> 7.3.492.27.1'
3030
spec.add_dependency 'method_source'
31-
spec.add_dependency 'mini_racer', '~> 0.2.4'
31+
spec.add_dependency 'mini_racer', '~> 0.2.6'
3232
spec.add_dependency 'opal', '>= 0.11.0', '< 0.12.0'
3333
spec.add_dependency 'parser', '>= 2.3.3.1'
3434
spec.add_dependency 'pry'

ruby/hyper-store/hyper-store.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
2929
spec.add_development_dependency 'hyper-component', Hyperstack::Legacy::Store::VERSION
3030
spec.add_development_dependency 'hyper-spec', Hyperstack::Legacy::Store::VERSION
3131
spec.add_development_dependency 'listen'
32-
spec.add_development_dependency 'mini_racer', '~> 0.2.4'
32+
spec.add_development_dependency 'mini_racer', '~> 0.2.6'
3333
spec.add_development_dependency 'opal-browser', '~> 0.2.0'
3434
spec.add_development_dependency 'opal-rails', '~> 0.9.4'
3535
spec.add_development_dependency 'pry-byebug'

ruby/hyperstack-config/hyperstack-config.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
2323
spec.require_paths = ['lib']
2424

2525
spec.add_dependency 'listen', '~> 3.0' # for hot loader
26-
spec.add_dependency 'mini_racer', '~> 0.2.4'
26+
spec.add_dependency 'mini_racer', '~> 0.2.6'
2727
spec.add_dependency 'opal', '>= 0.11.0', '< 0.12.0'
2828
spec.add_dependency 'opal-browser', '~> 0.2.0'
2929
spec.add_dependency 'uglifier'

ruby/rails-hyperstack/rails-hyperstack.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ You can control how much of the stack gets installed as well:
6161

6262
spec.add_dependency 'opal-browser', '~> 0.2.0'
6363
spec.add_dependency 'react-rails', '>= 2.4.0', '< 2.5.0'
64-
spec.add_dependency 'mini_racer', '~> 0.2.4'
65-
spec.add_dependency 'libv8', '~> 6.7.0'
64+
spec.add_dependency 'mini_racer', '~> 0.2.6'
65+
spec.add_dependency 'libv8', '~> 7.3.492.27.1'
6666
spec.add_dependency 'rails', '>= 4.0.0'
6767

6868

0 commit comments

Comments
 (0)