From e293ec4ee547cf02f656500d59e85e93f75196e8 Mon Sep 17 00:00:00 2001 From: Andy Maleh Date: Sun, 30 Jun 2024 18:36:46 -0400 Subject: [PATCH] Version 2.7.8 changes (data-binding improvements): - Allow passing `BindExpression` only 1 argument (e.g. presenter.todos) or 1 argument + 1 hash (e.g. presenter.todos, on_read: -> {}) - `ObserveExpression` always uses `ModelBinding` for arguments to leverage its advanced features, like nested/computed/indexed/keyed data-binding - In Opal, `ModelBinding` converters/hooks do not require an argument anymore (e.g. can invoke `after_write: -> { do_something }` without block args) - Fix issue whereby observing `model, :collection` was not firing on collection changes, but observing `model.collection` was firing on collection changes (now both fire on collection changes) --- CHANGELOG.md | 7 ++++ Gemfile | 2 +- README.md | 4 +-- Rakefile | 2 +- TODO.md | 3 +- VERSION | 2 +- glimmer.gemspec | 34 ++++++++++---------- lib/glimmer/data_binding/model_binding.rb | 9 ++---- lib/glimmer/data_binding/observable_model.rb | 3 +- lib/glimmer/dsl/bind_expression.rb | 12 +++++-- lib/glimmer/dsl/observe_expression.rb | 6 +--- 11 files changed, 47 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55e0ef619..e23624618 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ Related Change Logs: - [glimmer-dsl-swt/CHANGELOG.md](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/CHANGELOG.md) +### 2.7.8 + +- Allow passing `BindExpression` only 1 argument (e.g. presenter.todos) or 1 argument + 1 hash (e.g. presenter.todos, on_read: -> {}) +- `ObserveExpression` always uses `ModelBinding` for arguments to leverage its advanced features, like nested/computed/indexed/keyed data-binding +- In Opal, `ModelBinding` converters/hooks do not require an argument anymore (e.g. can invoke `after_write: -> { do_something }` without block args) +- Fix issue whereby observing `model, :collection` was not firing on collection changes, but observing `model.collection` was firing on collection changes (now both fire on collection changes) + ### 2.7.7 - Relax `array_include_methods` gem dependency to '>= 1.4.0', '< 1.6.0' diff --git a/Gemfile b/Gemfile index 9d3f10212..bd677589d 100644 --- a/Gemfile +++ b/Gemfile @@ -9,7 +9,7 @@ gem 'facets', '>= 3.1.0', '< 4.0.0', require: false group :development do gem 'rspec-mocks', '~> 3.5.0' gem 'rspec', '~> 3.5.0' - gem 'puts_debuggerer', '~> 0.13', require: false + gem 'puts_debuggerer', '>= 1.0.1', require: false gem 'rake', '>= 10.1.0', '< 14.0.0' gem 'jeweler', '>= 2.0.0', '< 3.0.0' gem 'rdoc', '>= 6.2.1', '< 7.0.0' diff --git a/README.md b/README.md index a84a32d02..641156d8d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# [](https://rubygems.org/gems/glimmer) Glimmer 2.7.7 +# [](https://rubygems.org/gems/glimmer) Glimmer 2.7.8 ## DSL Framework for Ruby GUI and More [![Gem Version](https://badge.fury.io/rb/glimmer.svg)](http://badge.fury.io/rb/glimmer) [![rspec](https://github.com/AndyObtiva/glimmer/workflows/rspec/badge.svg)](https://github.com/AndyObtiva/glimmer/actions?query=workflow%3Arspec) @@ -268,7 +268,7 @@ end ### Setup Follow these steps to author a [Glimmer](https://rubygems.org/gems/glimmer) DSL: -- Add `gem 'glimmer', '~> 2.7.7'` to `Gemfile` and run `bundle` or run `gem install glimmer -v2.7.7` and add `require 'glimmer'` +- Add `gem 'glimmer', '~> 2.7.8'` to `Gemfile` and run `bundle` or run `gem install glimmer -v2.7.8` and add `require 'glimmer'` - Create `glimmer/dsl/[dsl_name]/dsl.rb`, which requires and adds all dynamic expressions for the [dsl_name] Glimmer DSL module as per the code shown in the previous section (or [Official DSLs](#official-dsls) as examples) - Create `glimmer/dsl/[dsl_name]/[expresion_name]_expresion.rb` for every [expresion_name] expression needed, whether dynamic or static diff --git a/Rakefile b/Rakefile index 06587e20b..d5ab68911 100644 --- a/Rakefile +++ b/Rakefile @@ -22,7 +22,7 @@ unless jeweler_required.nil? gem.homepage = "http://github.com/AndyObtiva/glimmer" gem.license = "MIT" gem.summary = %Q{Glimmer (DSL Framework for Ruby GUI and More)} - gem.description = %Q{Glimmer is a Ruby DSL Framework for Ruby GUI and More, consisting of a DSL Engine and a Data-Binding Library (including Observer Design Pattern, Observable Model, Observable Array, and Observable Hash). Used in Glimmer DSL for SWT (JRuby Desktop Development GUI Framework), Glimmer DSL for Opal (Pure Ruby Web GUI and Auto-Webifier of Desktop Apps), Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library and Winner of Fukuoka Ruby Award Competition 2022 Special Award), Glimmer DSL for Tk (Ruby Tk Desktop Development GUI Library), Glimmer DSL for GTK (Ruby-GNOME Desktop Development GUI Library), Glimmer DSL for FX (FOX Toolkit Ruby Desktop Development GUI Library), Glimmer DSL for WX (wxWidgets Ruby Desktop Development GUI Library), Glimmer DSL for Swing (JRuby Swing Desktop Development GUI Library), Glimmer DSL for JFX (JRuby JavaFX Desktop Development GUI Library), Glimmer DSL for XML (& HTML), and Glimmer DSL for CSS.} + gem.description = %Q{Glimmer is a Ruby DSL Framework for Ruby GUI and More, consisting of a DSL Engine and a Data-Binding Library (including Observer Design Pattern, Observable Model, Observable Array, and Observable Hash). Used in Glimmer DSL for SWT (JRuby Desktop Development GUI Framework), Glimmer DSL for Web (Ruby in the Browser Web Frontend Framework), Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library and Winner of Fukuoka Ruby Award Competition 2022 Special Award), Glimmer DSL for Tk (Ruby Tk Desktop Development GUI Library), Glimmer DSL for GTK (Ruby-GNOME Desktop Development GUI Library), Glimmer DSL for FX (FOX Toolkit Ruby Desktop Development GUI Library), Glimmer DSL for WX (wxWidgets Ruby Desktop Development GUI Library), Glimmer DSL for Swing (JRuby Swing Desktop Development GUI Library), Glimmer DSL for JFX (JRuby JavaFX Desktop Development GUI Library), Glimmer DSL for XML (& HTML), and Glimmer DSL for CSS.} gem.email = "andy.am@gmail.com" gem.authors = ["AndyMaleh"] # gem.executables = ['glimmer', 'girb'] # moved to glimmer-dsl-swt for now diff --git a/TODO.md b/TODO.md index 9db9a2caf..905d92dcf 100644 --- a/TODO.md +++ b/TODO.md @@ -9,10 +9,11 @@ Related TODO files: ## Next +- Observe an array or nested arrays for all children changes on a specific property (e.g. observe(@game, 'tetris_blocks[][].color') ; returns |new_color, tetris_block| / observe(@game.players, '[].name') ; returns |name, player|) +- Observe multiple attributes (e.g. observe(@game, [:width, :height]) returns |value, attribute_name|) - Fix issue with computed data-binding when combined with nested/indexed data-binding (it looks up computed attributes on root object instead of nested object, it seems) - Support nested computed attributes (e.g. computed_by: {address1: [:street, :city, :state, :zip]}) - Consider the idea of having Observer#observe accept an optional block to do observation without implementing `call` (kinda like when using the `observe` keyword in the Glimmer DSL). -- Observe an array for all children changes on a specific property (e.g. observe(@game, 'blocks[][].color') ; returns |new_color, block|) - Ensure removing observers from hash in ObservableModel when removed from observable - Avoid `< Struct.new` in specs (tests) - Add built-in support to Glimmer::DSL::Engine to memoize/cache expressions similar to how that is supported for StaticExpression (but allowing an outside keyword and non-static expression to be used) diff --git a/VERSION b/VERSION index 1f7da99d4..6a81b4c83 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.7.7 +2.7.8 diff --git a/glimmer.gemspec b/glimmer.gemspec index 693288f84..73b99666f 100644 --- a/glimmer.gemspec +++ b/glimmer.gemspec @@ -2,17 +2,17 @@ # DO NOT EDIT THIS FILE DIRECTLY # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' # -*- encoding: utf-8 -*- -# stub: glimmer 2.7.7 ruby lib +# stub: glimmer 2.7.8 ruby lib Gem::Specification.new do |s| s.name = "glimmer".freeze - s.version = "2.7.7".freeze + s.version = "2.7.8" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["AndyMaleh".freeze] - s.date = "2024-01-10" - s.description = "Glimmer is a Ruby DSL Framework for Ruby GUI and More, consisting of a DSL Engine and a Data-Binding Library (including Observer Design Pattern, Observable Model, Observable Array, and Observable Hash). Used in Glimmer DSL for SWT (JRuby Desktop Development GUI Framework), Glimmer DSL for Opal (Pure Ruby Web GUI and Auto-Webifier of Desktop Apps), Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library and Winner of Fukuoka Ruby Award Competition 2022 Special Award), Glimmer DSL for Tk (Ruby Tk Desktop Development GUI Library), Glimmer DSL for GTK (Ruby-GNOME Desktop Development GUI Library), Glimmer DSL for FX (FOX Toolkit Ruby Desktop Development GUI Library), Glimmer DSL for WX (wxWidgets Ruby Desktop Development GUI Library), Glimmer DSL for Swing (JRuby Swing Desktop Development GUI Library), Glimmer DSL for JFX (JRuby JavaFX Desktop Development GUI Library), Glimmer DSL for XML (& HTML), and Glimmer DSL for CSS.".freeze + s.date = "2024-07-01" + s.description = "Glimmer is a Ruby DSL Framework for Ruby GUI and More, consisting of a DSL Engine and a Data-Binding Library (including Observer Design Pattern, Observable Model, Observable Array, and Observable Hash). Used in Glimmer DSL for SWT (JRuby Desktop Development GUI Framework), Glimmer DSL for Web (Ruby in the Browser Web Frontend Framework), Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library and Winner of Fukuoka Ruby Award Competition 2022 Special Award), Glimmer DSL for Tk (Ruby Tk Desktop Development GUI Library), Glimmer DSL for GTK (Ruby-GNOME Desktop Development GUI Library), Glimmer DSL for FX (FOX Toolkit Ruby Desktop Development GUI Library), Glimmer DSL for WX (wxWidgets Ruby Desktop Development GUI Library), Glimmer DSL for Swing (JRuby Swing Desktop Development GUI Library), Glimmer DSL for JFX (JRuby JavaFX Desktop Development GUI Library), Glimmer DSL for XML (& HTML), and Glimmer DSL for CSS.".freeze s.email = "andy.am@gmail.com".freeze s.extra_rdoc_files = [ "CHANGELOG.md", @@ -53,22 +53,22 @@ Gem::Specification.new do |s| ] s.homepage = "http://github.com/AndyObtiva/glimmer".freeze s.licenses = ["MIT".freeze] - s.rubygems_version = "3.5.3".freeze + s.rubygems_version = "3.4.10".freeze s.summary = "Glimmer (DSL Framework for Ruby GUI and More)".freeze s.specification_version = 4 - s.add_runtime_dependency(%q.freeze, [">= 1.4.0".freeze, "< 1.6.0".freeze]) - s.add_runtime_dependency(%q.freeze, [">= 3.1.0".freeze, "< 4.0.0".freeze]) - s.add_development_dependency(%q.freeze, ["~> 3.5.0".freeze]) - s.add_development_dependency(%q.freeze, ["~> 3.5.0".freeze]) - s.add_development_dependency(%q.freeze, ["~> 0.13".freeze]) - s.add_development_dependency(%q.freeze, [">= 10.1.0".freeze, "< 14.0.0".freeze]) - s.add_development_dependency(%q.freeze, [">= 2.0.0".freeze, "< 3.0.0".freeze]) - s.add_development_dependency(%q.freeze, [">= 6.2.1".freeze, "< 7.0.0".freeze]) - s.add_development_dependency(%q.freeze, [">= 0".freeze]) - s.add_development_dependency(%q.freeze, ["~> 0.16.1".freeze]) - s.add_development_dependency(%q.freeze, ["~> 0.7.0".freeze]) - s.add_development_dependency(%q.freeze, ["> 0".freeze]) + s.add_runtime_dependency(%q.freeze, [">= 1.4.0", "< 1.6.0"]) + s.add_runtime_dependency(%q.freeze, [">= 3.1.0", "< 4.0.0"]) + s.add_development_dependency(%q.freeze, ["~> 3.5.0"]) + s.add_development_dependency(%q.freeze, ["~> 3.5.0"]) + s.add_development_dependency(%q.freeze, [">= 1.0.1"]) + s.add_development_dependency(%q.freeze, [">= 10.1.0", "< 14.0.0"]) + s.add_development_dependency(%q.freeze, [">= 2.0.0", "< 3.0.0"]) + s.add_development_dependency(%q.freeze, [">= 6.2.1", "< 7.0.0"]) + s.add_development_dependency(%q.freeze, [">= 0"]) + s.add_development_dependency(%q.freeze, ["~> 0.16.1"]) + s.add_development_dependency(%q.freeze, ["~> 0.7.0"]) + s.add_development_dependency(%q.freeze, ["> 0"]) end diff --git a/lib/glimmer/data_binding/model_binding.rb b/lib/glimmer/data_binding/model_binding.rb index 62e4896bb..d54aeafdf 100644 --- a/lib/glimmer/data_binding/model_binding.rb +++ b/lib/glimmer/data_binding/model_binding.rb @@ -131,6 +131,8 @@ def nested_property_observers_for(observer) end def add_observer(observer, extra_options = {}) + # TODO couldn't we have a scenario where it is both computed? and nested_property? at the same time? + # or computed and not nested at the same time (else statement)? if computed? add_computed_observers(observer) elsif nested_property? @@ -252,12 +254,7 @@ def apply_processor(processor, value) def invoke_proc_with_exact_parameters(proc_object, *args) return if proc_object.nil? - if RUBY_ENGINE == 'opal' - # opal doesn't support proc_object.parameters.size properly it seems - args = Concurrent::Array.new(args[0...1]) - else - args = Concurrent::Array.new(args[0...proc_object.parameters.size]) - end + args = Concurrent::Array.new(args[0...proc_object.parameters.size]) proc_object.call(*args) end diff --git a/lib/glimmer/data_binding/observable_model.rb b/lib/glimmer/data_binding/observable_model.rb index 2a2042356..54ff1c9b9 100644 --- a/lib/glimmer/data_binding/observable_model.rb +++ b/lib/glimmer/data_binding/observable_model.rb @@ -54,6 +54,7 @@ def add_observer(observer, property_name, options = {}) initialize_observer_options(options) return observer if has_observer?(observer, property_name) property_observer_list(property_name) << observer + # if property writer does not exist, add_property_writer_observers will ensure_array_object_observer only add_property_writer_observers(property_name, options) open_struct_loaded = !!::OpenStruct rescue false add_key_writer_observer(property_name, options) if is_a?(Struct) || (open_struct_loaded && is_a?(OpenStruct)) @@ -116,8 +117,8 @@ def add_property_writer_observers(property_name, options) options[:attribute_writer_type].each do |attribute_writer_type| begin property_writer_name = attribute_writer_type.to_s.gsub('attribute', property_name.to_s) - method(property_writer_name) ensure_array_object_observer(property_name, send(property_name), nil, options) + method(property_writer_name) begin method("__original__#{property_writer_name}") rescue diff --git a/lib/glimmer/dsl/bind_expression.rb b/lib/glimmer/dsl/bind_expression.rb index 6f025c5b4..a9b8ecc64 100644 --- a/lib/glimmer/dsl/bind_expression.rb +++ b/lib/glimmer/dsl/bind_expression.rb @@ -31,9 +31,16 @@ def can_interpret?(parent, keyword, *args, &block) ( keyword == 'bind' and ( + ( + (args.size == 1) + ) || ( (args.size == 2) and textual?(args[1]) + ) || + ( + (args.size == 2) and + (args[1].is_a?(Hash)) ) || ( (args.size == 3) and @@ -43,11 +50,12 @@ def can_interpret?(parent, keyword, *args, &block) ) ) end + def interpret(parent, keyword, *args, &block) - binding_options = args[2] || {} + binding_options = args.last.is_a?(Hash) ? args.pop : {} binding_options[:on_read] = binding_options.delete(:on_read) || binding_options.delete('on_read') || block - DataBinding::ModelBinding.new(args[0], args[1].to_s, binding_options) + DataBinding::ModelBinding.new(*args, binding_options) end end end diff --git a/lib/glimmer/dsl/observe_expression.rb b/lib/glimmer/dsl/observe_expression.rb index c67ba517b..38003114b 100644 --- a/lib/glimmer/dsl/observe_expression.rb +++ b/lib/glimmer/dsl/observe_expression.rb @@ -36,11 +36,7 @@ def can_interpret?(parent, keyword, *args, &block) def interpret(parent, keyword, *args, &block) observer = DataBinding::Observer.proc(&block) - if args[1].to_s.match(REGEX_NESTED_OR_INDEXED_PROPERTY) - observer_registration = observer.observe(DataBinding::ModelBinding.new(*args)) - else - observer_registration = observer.observe(*args) - end + observer_registration = observer.observe(DataBinding::ModelBinding.new(*args)) observer_registration end end