-
Notifications
You must be signed in to change notification settings - Fork 5
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
JS Rewrite #6
base: ivans-updates
Are you sure you want to change the base?
JS Rewrite #6
Conversation
I've answered a few questions on this on the forum already. Working with Lists in JavaScript is awkward compared to the other languages. The options, as far as I can tell are to:
I wonder if it makes sense to have a separate language specific library file where we can put stuff like what one would need to write to address this awkwardness that only exists in JavaScript. Python's list comprehensions and built in list manipulation functions work just fine. WDT? It would probably be a part of a separate PR but since you are rewriting the lib anyway maybe it makes sense to add that as part of this. |
Have you see the Java |
That works for forEach. But not for filter, findFirst, map and reduce all of which are operations people are used to doing, particularly with members of a Group. forEach is available in those Classes that implement the Iterable interface (basically Lists and Sets). If one is just going to iterate over the elements that would for sure be better. But for the rest the only way I've seen to do it without hand coding the loops is to use the streams API. And the streams API isn't really all bad and I'm sure we can hide much of the oddness (when compared to how it works in Jython and Rules DSL) through some library calls. The big gotcha is the need to import a Collector and using that to convert the stream back into List. |
An interesting problem for sure, we will need to do some experiments. I stopped using all of those functions when I left DSL rules, but then again I'm using to programming in CPython where those don't exist so I just do what I know. |
They exist in Python as well, though they have largely been replaced with list comprehensions as the more Pythonic approach. https://www.learnpython.org/en/Map,_Filter,_Reduce. |
Originally noted here |
Have there been any updates to the Java helper libraires for OH3? While i am able to load these and get a basic rule to load it looks like a lot of the helper functions are still missing? |
I have no major work done that is not available in this branch. At present I have no timeline to continue the work either. That said, if you submit a PR to this branch I can merge it without much need to test myself since this branch is in development and there is no expectation of functionality yet. |
Would it make sense to just call this as done as it's going to be? Nashorn is not going to be supported by OH any longer once they move to Java 17 (or whatever they jump to) so maybe it makes sense to deprecate the JS libraries entirely and point people to JS Scripting. We should obviously not remove the library for now so those with legacy systems and set ups that can't or wont move will still have access to it, but I feel like we should warn people away from starting with this now and I'm not sure continuing the work to bring it to parity with Jython is worth while any longer. Jython's future too is murky but not as certain to go away as Nashorn so I'd encourage the continued maintenance and development on it. I don't think there ever was any Groovy stuff, but its future is probably the most certain of the three. |
This is an (almost) complete rewrite of the JavaScript/ES5 portion of the libraries to bring them in line with the features available in the Python libraries.
Work in Progress not everything here has been tested, not everything from Python has been ported yet, and in its current state this version is not backwards compatible with the current JS libraries! You have been warned.
To-Do:
PersistenceExtensions.js
actions.js
more inline with original/jythonconditions.js
date.py
to JSproviders.js
rules.js
(or do we?)triggers.js
(or do we?)utils.js
(or do we?)