Many FP metods, such as c.find() require a closure to filter the results. I am trying to implement something in javascript but cannot get anything to work. AFAIK the closure should return a boolean but just inserting a javasript boolean test does not work.
For example c.find(true)produces a type error saying the parameters do not match any of the method options. I would have expected it to return the same as c.findAll().
I can do a c.findAll() then fliter the resulting list in this case but there are other methods where I cannot find a simple solution such as node.sortChildrenBy().
There is also the question of passing the object to be tested, in javascript it is not defined.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I appreciate this, and accept that some things may be harder. However, using a language you are more familiar with makes other things much easier and that is generlly where I work. I don't mind the edge cases being a bit harder since having to convert a whole script is possibly harder still.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
varcondition=neworg.freeplane.api.NodeCondition(){check:function(node){returnnode.text.length()>3}};varnodes=c.find(condition);node.text="I have found "+nodes.size()+" nodes"
It works but... not so convenient !
👍
1
Last edit: lilive 2021-03-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just had a chance to give this a try and it does exactly what I was looking for so thanks very much.
Given that a NodeCondition test needs writing anyway it only adds a couple of extra lines of code to add the class instance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Many FP metods, such as c.find() require a closure to filter the results. I am trying to implement something in javascript but cannot get anything to work. AFAIK the closure should return a boolean but just inserting a javasript boolean test does not work.
For example
c.find(true)
produces a type error saying the parameters do not match any of the method options. I would have expected it to return the same asc.findAll()
.I can do a
c.findAll()
then fliter the resulting list in this case but there are other methods where I cannot find a simple solution such asnode.sortChildrenBy()
.There is also the question of passing the object to be tested, in javascript
it
is not defined.Groovy is the preferred language for Freeplane. Some things may not be as easy to do with the other languages.
I appreciate this, and accept that some things may be harder. However, using a language you are more familiar with makes other things much easier and that is generlly where I work. I don't mind the edge cases being a bit harder since having to convert a whole script is possibly harder still.
Hi,
I have tried and found something.
The API documentation say that find() can be use with a NodeCondition.
How to create a class the implement this java interface ? The wiki speaks about a JSS 223 adapter. What the hell ? I've found this Oracle doc chapter. It explains how to implement interfaces.
In the end, I was really surprised to succeed !
It works but... not so convenient !
Last edit: lilive 2021-03-17
That's great, thanks for digging it out I will take a look.
Just had a chance to give this a try and it does exactly what I was looking for so thanks very much.
Given that a NodeCondition test needs writing anyway it only adds a couple of extra lines of code to add the class instance.