-
Notifications
You must be signed in to change notification settings - Fork 55
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
Easier JS Syntax #396
Easier JS Syntax #396
Conversation
to_a now converts datatypes inside array to ruby
…a lot of mistakes. mine included
…Fix respond_to_missing
…ill run into hard to debug bugs (js string include? etc)
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.
Sorry, I don't have enough time to review all changes, but as a general feedback, would you mind splitting changes into smaller PRs and writing tests to cover new functionalities? It helps me a lot to review and I think it will give you some insights on edge cases.
|
||
# Try to convert JS Objects into Ruby Objects | ||
# Todo: make a list of Types that need to remain JS::Objects (array methods?) | ||
def to_rb |
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.
As you noticed, there is no obvious mapping from JavaScript objects to Ruby objects. Also for most use cases, what we really need is conversion to a specific type like to_i
and to_s
. So TBH I'm not sure if it's worth introducing this kind of generic conversion method.
# Support self == true instead of self == JS:True | ||
alias_method :orig_eq, :== | ||
def ==(other) |
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.
How about comparing self
with other.to_js
?
|
||
def each(&block) | ||
if block_given? | ||
self.isJSArray ? self.to_a.each(&block) : Array.new(__props).each(&block) |
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.
Hmm, I feel iterating on object properties is a little bit tricky. Do you have any use case for this behavior? I prefer simply delegating to self.to_a.each
I accidentaly closed this. I'm working on a new version that will be easier to review! |
** Sorry, This is only a draft. Any help to improve this is welcome**
Todo:
I'm using this in my projects: Ruby Koans on the Browser
Ruby.wasm Quickstart
Using method missing for allowing easier JS syntax. #228
Shopping List Example code: