-
Notifications
You must be signed in to change notification settings - Fork 0
Basic app #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Basic app #1
Changes from 8 commits
4f5fcd8
0346c81
7015dc1
57e0bfc
3076b40
571afb3
26f2ed0
392b92d
fbad9e5
67fda53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,5 +57,7 @@ build-iPhoneSimulator/ | |
|
|
||
| *.dll | ||
| *.so | ||
| *.exp | ||
| *.lib | ||
|
|
||
| .vscode | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| @echo off | ||
| set RUBY_DLL_PATH=%CD% | ||
| echo RUBY_DLL_PATH set to %RUBY_DLL_PATH% | ||
| ruby main.rb |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| $env:RUBY_DLL_PATH = Get-Location | ||
| Write-Output "RUBY_DLL_PATH set to $env:RUBY_DLL_PATH" | ||
| ruby main.rb |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| require 'rx' | ||
| require_relative 'theme' | ||
| require_relative 'widgetnode' | ||
| require 'thread' | ||
| require 'concurrent-ruby' | ||
|
|
||
| class TodoItem | ||
| attr_accessor :text, :done | ||
|
|
||
| def initialize(text, done) | ||
| @text = text | ||
| @done = done | ||
| end | ||
| end | ||
|
|
||
| class AppState | ||
| attr_accessor :todo_text, :todo_items | ||
|
|
||
| def initialize(todo_text, todo_items) | ||
| @todo_text = todo_text | ||
| @todo_items = todo_items | ||
| end | ||
| end | ||
|
|
||
| $sample_app_state = Rx::BehaviorSubject.new(AppState.new("", [])) | ||
|
Comment on lines
+16
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Encapsulate application state within a service class. Using a global variable ( -$sample_app_state = Rx::BehaviorSubject.new(AppState.new("", []))
+class TodoService
+ def self.instance
+ @instance ||= new
+ end
+
+ def initialize
+ @state = Rx::BehaviorSubject.new(AppState.new("", []))
+ end
+
+ def state
+ @state
+ end
+
+ private_class_method :new
+endThis provides better encapsulation and follows the Singleton pattern. |
||
|
|
||
| def on_click | ||
| new_todo_item = TodoItem.new("New Todo", false) | ||
|
|
||
| current_state = $sample_app_state.value | ||
|
|
||
| new_state = AppState.new( | ||
| current_state.todo_text, | ||
| current_state.todo_items + [new_todo_item] | ||
| ) | ||
|
|
||
| $sample_app_state.on_next(new_state) | ||
| end | ||
|
|
||
| $text_style = WidgetStyle.new( | ||
| style: WidgetStyleDef.new( | ||
| style_rules: StyleRules.new( | ||
| font: FontDef.new(name: "roboto-regular", size: 32) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| $button_style = WidgetStyle.new( | ||
| style: WidgetStyleDef.new( | ||
| style_rules: StyleRules.new( | ||
| font: FontDef.new(name: "roboto-regular", size: 32) | ||
| ), | ||
| layout: YogaStyle.new( | ||
| width: "50%", | ||
| padding: {Edge[:Vertical] => 10}, | ||
| margin: {Edge[:Left] => 140} | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| class App < BaseComponent | ||
| def initialize | ||
| super({}) | ||
|
|
||
| @sample_app_state = Rx::BehaviorSubject.new(AppState.new("", [])) | ||
|
|
||
| @props.on_next({ | ||
| "todo_text" => "", | ||
| "todo_items" => [] | ||
| }) | ||
|
|
||
| puts "App initialize called 3" | ||
|
|
||
| promise = Concurrent::Promise.execute do | ||
| @sample_app_state.subscribe do |latest_app_state| | ||
| # Safe operation, as Async ensures execution is handled in the appropriate thread | ||
| @props.on_next({ | ||
| "todo_text" => latest_app_state.todo_text, | ||
| "todo_items" => latest_app_state.todo_items | ||
| }) | ||
| end | ||
| end | ||
|
|
||
| # Wait for the promise to complete before moving forward | ||
| promise.wait | ||
|
|
||
| puts "App initialize called 4" | ||
| end | ||
|
|
||
| def render | ||
| puts "App render called" | ||
| children = [button("Add todo", Proc.new {puts "suga"}, $button_style)] | ||
| # children = [button("Add todo")] | ||
|
|
||
| puts "App render called 2" | ||
|
|
||
| # props.value["todo_items"].each do |todo_item| | ||
| # text = "#{todo_item.text} (#{todo_item.done ? 'done' : 'to do'})." | ||
| # children << unformatted_text(text, $text_style) | ||
| # children << unformatted_text(text) | ||
| # end | ||
|
|
||
| puts "App render called 3" | ||
|
|
||
| node(children) | ||
| end | ||
|
|
||
| def dispose | ||
| @app_state_subscription.dispose | ||
| end | ||
| end | ||
|
|
||
| class Root < BaseComponent | ||
| def initialize | ||
| super({}) | ||
| end | ||
|
|
||
| def render | ||
| root_node([App.new]) | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Verify the dependencies are properly installed.
Please ensure that all required gems are listed in the project's Gemfile:
Run this script to check the dependencies:
🏁 Script executed:
Length of output: 245
Missing Dependency: "rx" gem Not Installed
• The dependency check confirms that "concurrent-ruby" (v1.3.5) is properly installed.
• However, the gem "rx" required by the file (via
require 'rx') is missing from the installed gems list.• Please ensure that the project's Gemfile includes
gem 'rx'(expected latest version "0.0.3") and install it accordingly.