summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorStephan Bergmann <stephan.bergmann@allotropia.de>2024-06-04 17:04:14 +0200
committerStephan Bergmann <stephan.bergmann@allotropia.de>2024-06-05 08:08:58 +0200
commitb4f416abc245ae63c164d51ee9fd4d4c849e0411 (patch)
tree6b5cdbaea732a0ddf7a0f628dcea96873d0a2394 /static
parent44e618096511e8f6e0a6344fab19403503c25148 (diff)
Clean up example code
* Consistently use `const` to introduce variable bindings. * Don't rely on `xText` from the first example in the second one. * No (more) need to query for base interfaces. * No (more) need to delete interface references. * Add a missing delete of Any `next`. * Remove a redundant empty line. * Adapt to our 100 character line width. Change-Id: Ie116021a4b0cc6d88c6204e7ea5147a837c251f5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168405 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Diffstat (limited to 'static')
-rw-r--r--static/README.wasm.md45
1 files changed, 21 insertions, 24 deletions
diff --git a/static/README.wasm.md b/static/README.wasm.md
index 5a247b085a0d..c07c3a9a389c 100644
--- a/static/README.wasm.md
+++ b/static/README.wasm.md
@@ -210,35 +210,32 @@ improvement! ;)
Some usage examples through javascript of the current implementation:
```js
// inserts a string at the start of the Writer document.
-let uno = init_unoembind_uno(Module);
-let css = uno.com.sun.star;
-xModel = Module.getCurrentModelFromViewSh();
-xTextDocument = css.text.XTextDocument.query(xModel);
-xText = xTextDocument.getText();
-xSimpleText = css.text.XSimpleText.query(xText);
-xTextCursor = xSimpleText.createTextCursor();
-xTextRange = css.text.XTextRange.query(xTextCursor);
-xTextRange.setString("string here!");
-xModel.delete(); xTextDocument.delete(); xText.delete(); xSimpleText.delete(); xTextCursor.delete(); xTextRange.delete();
+const uno = init_unoembind_uno(Module);
+const css = uno.com.sun.star;
+const xModel = Module.getCurrentModelFromViewSh();
+const xTextDocument = css.text.XTextDocument.query(xModel);
+const xText = xTextDocument.getText();
+const xTextCursor = xText.createTextCursor();
+xTextCursor.setString("string here!");
```
```js
// changes each paragraph of the Writer document to a random color.
-let uno = init_unoembind_uno(Module);
-let css = uno.com.sun.star;
-xModel = Module.getCurrentModelFromViewSh();
-xEnumAccess = css.container.XEnumerationAccess.query(xText);
-xParaEnumeration = xEnumAccess.createEnumeration();
-
+const uno = init_unoembind_uno(Module);
+const css = uno.com.sun.star;
+const xModel = Module.getCurrentModelFromViewSh();
+const xTextDocument = css.text.XTextDocument.query(xModel);
+const xText = xTextDocument.getText();
+const xEnumAccess = css.container.XEnumerationAccess.query(xText);
+const xParaEnumeration = xEnumAccess.createEnumeration();
while (xParaEnumeration.hasMoreElements()) {
- xParagraph = css.text.XTextRange.query(xParaEnumeration.nextElement().get());
- if (xParagraph !== null) {
- xParaProps = css.beans.XPropertySet.query(xParagraph);
- let color = new Module.uno_Any(
- Module.uno_Type.Long(), Math.floor(Math.random() * 0xFFFFFF));
- xParaProps.setPropertyValue("CharColor", color);
- color.delete();
- }
+ const next = xParaEnumeration.nextElement();
+ const xParagraph = css.text.XTextRange.query(next.get());
+ const xParaProps = css.beans.XPropertySet.query(xParagraph);
+ const color = new Module.uno_Any(Module.uno_Type.Long(), Math.floor(Math.random() * 0xFFFFFF));
+ xParaProps.setPropertyValue("CharColor", color);
+ next.delete();
+ color.delete();
}
```