Skip to content
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

This PR is implementing the another "result" function for the $ (selector) function . #1549

Merged
merged 1 commit into from
May 3, 2024

Conversation

PeterVoronov
Copy link
Contributor

The new "result" function toArray() returns an array of strings which is an usual array with has all selected id's and you can apply all appropriate arrays methods to it.
The reason of this PR - in some cases, you need to get the array of strings from the selector, instead of use the current each iterator. Moreover, the source data already presented as an array of strings, so you don't need to iterate it once more time.
Changed files:

  • lib/javascript.d.ts: updated declaration of $ - the `toArray() is added;
  • lib/sandbox.js: implementation of the toArray() function;
  • test/testFunctions.js: test added for the toArray() function;
  • docs/en/javascript.md: documentation updates of the $ function description.

…elector`) function .

The new "result" function `toArray()` returns an `array of strings` which is an usual array with has all selected `id's` and you can apply all appropriate arrays methods to it.
The reason of this PR - in some cases, you need to get the array of strings from the `selector`, instead of use the current `each` iterator. Moreover, the source data already presented as an array of strings, so you don't need to iterate it once more time.
Changed files:
- `lib/javascript.d.ts`: updated declaration of `$` - the `toArray() is added;
- `lib/sandbox.js`: implementation of the `toArray()` function;
- `test/testFunctions.js`: test added for the `toArray()` function;
- `docs/en/javascript.md`: documentation updates of the `$` function description.
@klein0r klein0r merged commit 5bd97ac into ioBroker:master May 3, 2024
12 checks passed
@klein0r
Copy link
Collaborator

klein0r commented May 3, 2024

Thank you! This could the replace the weird Array.prototype.slice.apply($('0_userdata.0.*')) logic in some Blockly code

@PeterVoronov
Copy link
Contributor Author

Thank you! This could the replace the weird Array.prototype.slice.apply($('0_userdata.0.*')) logic in some Blockly code

You are always welcome!

@PeterVoronov PeterVoronov deleted the selector_to_array branch May 3, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants