Skip to content

Commit b4b1a36

Browse files
committed
📚 Update concrete expressions documentation
1 parent bd7ab06 commit b4b1a36

File tree

3 files changed

+42
-35
lines changed

3 files changed

+42
-35
lines changed

‎Sources/Expressions/JSFunction.swift

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,30 @@
66
import Foundation
77

88
///
9-
/// A concrete JavaScript expression that executes a function in the current JavaScript `this`. The
10-
/// function variable is represented by a key path relative to the current `this`.
9+
/// A JavaScript expression that executes a function in the current JavaScript `this`. The
10+
/// function variable is referenced by a key path relative to the current `this`.
1111
///
1212
/// For instance, to present an alert:
1313
///
1414
/// ~~~swift
15-
/// let alert = JSFreeFunction<Void>("window.alert", arguments: "Hello from Swift!")
16-
/// // equivalent to the JS script `this.window.alert("Hello from Swift!");`
15+
/// let alert = JSFunction<JSVoid>("window.alert", arguments: "Hello from Swift!")
16+
/// // equivalent to the JS script: `this.window.alert("Hello from Swift!");`
1717
/// ~~~
1818
///
1919
/// Instances of this class are specialized with the `T` generic parameter. It must be set to the
2020
/// return type of the JavaScript function to execute. Check the documentation of the JavaScript
2121
/// function to know what to set the parameter to.
2222
///
23-
/// `T` must be a compatible type. Compatible types include:
24-
/// - `Void`
25-
/// - Primitive values (`JSPrimitiveType`)
26-
/// - Enum cases with a primitive `RawValue`
27-
/// - Objects (`JSObject`)
23+
/// `T` must be a `Decodable` type. This includes:
24+
///
25+
/// - `JSVoid` for functions that do not return a value
26+
/// - Primitive values (Strings, Numbers, Booleans, ...)
27+
/// - Decodable enumerations
28+
/// - Objects decodable from JSON
2829
/// - Arrays of primitive values
29-
/// - Arrays of enum cases with a primitive `RawValue`
30-
/// - Arrays of objects.
30+
/// - Arrays of enumeration cases
31+
/// - Arrays of objects
32+
/// - Native dictionaries
3133
///
3234

3335
public final class JSFunction<T>: JSExpression where T: Decodable {
@@ -51,8 +53,8 @@ public final class JSFunction<T>: JSExpression where T: Decodable {
5153
/// For instance, to present an alert:
5254
///
5355
/// ~~~swift
54-
/// let alert = JSFreeFunction<Void>("window.alert", arguments: "Hello from Swift!")
55-
/// // equivalent to the JS script `this.window.alert("Hello from Swift!");`
56+
/// let alert = JSFunction<JSVoid>("window.alert", arguments: "Hello from Swift!")
57+
/// // equivalent to the JS script: `this.window.alert("Hello from Swift!");`
5658
/// ~~~
5759
///
5860

‎Sources/Expressions/JSScript.swift

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import Foundation
77

88
///
9-
/// A concrete JavaScript expression that executes a user-defined script. This class allows you to
10-
/// evaluate your own scripts.
9+
/// A JavaScript expression that executes a user-defined script. This class allows you to
10+
/// evaluate your own custom scripts.
1111
///
1212
/// For instance, to return the text of the longest <p> node in the current document:
1313
///
@@ -35,26 +35,30 @@ import Foundation
3535
/// type of the last statement in your script. In the above example, `findLongestText` has a return
3636
/// type of `String` because its last statement is a String (`longestInnerHTML`).
3737
///
38-
/// `T` must be a compatible type. Compatible types include:
39-
/// - `Void`
40-
/// - Primitive values (`JSPrimitiveType`)
41-
/// - Enum cases with a primitive `RawValue`
42-
/// - Objects (`JSObject`)
38+
/// `T` must be a `Decodable` type. This includes:
39+
///
40+
/// - `JSVoid` for scripts that do not return a value
41+
/// - Primitive values (Strings, Numbers, Booleans, ...)
42+
/// - Decodable enumerations
43+
/// - Objects decodable from JSON
4344
/// - Arrays of primitive values
44-
/// - Arrays of enum cases with a primitive `RawValue`
45-
/// - Arrays of objects.
45+
/// - Arrays of enumeration cases
46+
/// - Arrays of objects
47+
/// - Native dictionaries
4648
///
4749

4850
public final class JSScript<T>: JSExpression where T: Decodable {
49-
5051
public typealias ReturnType = T
52+
53+
/// The text of the script to execute.
5154
public let javaScriptString: String
5255

5356
///
5457
/// Creates a new custom script description with the script to execute.
5558
///
5659
/// - parameter javaScriptString: The script to run when evaluating this expression. It will
57-
/// be ran as is, make sure to check for syntax errors before creating the expression.
60+
/// be ran without modifications, so make sure to check for syntax errors and escape strings if
61+
/// necessary before creating the expression.
5862
///
5963

6064
public init(_ javaScriptString: String) {

‎Sources/Expressions/JSVariable.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,32 @@
66
import Foundation
77

88
///
9-
/// A concrete JavaScript expression that returns the value of a variable in the current JavaScript
10-
/// `this`. The variable is represented by a key path relative to the current `this`.
9+
/// A JavaScript expression that returns the value of a variable in the current JavaScript
10+
/// `this`. The variable is referenced by a key path relative to the current `this`.
1111
///
1212
/// For instance, to get the title of the current document:
1313
///
1414
/// ~~~swift
1515
/// let title = JSVariable<String>("document.title")
16-
/// // equivalent to the JS script `this.document.title;`
16+
/// // equivalent to the JS script: `this.document.title;`
1717
/// ~~~
1818
///
1919
/// Instances of this class are specialized with the `T` generic parameter. It must be set to the
2020
/// type of the JavaScript variable to query. Check the documentation of the JavaScript variable
2121
/// to know what to set the parameter to.
2222
///
23-
/// `T` must be a compatible type. Compatible types include:
24-
/// - Primitive values (`JSPrimitiveType`)
25-
/// - Enum cases with a primitive `RawValue`
26-
/// - Objects (`JSObject`)
23+
/// `T` must be a `Decodable` type. This includes:
24+
///
25+
/// - Primitive values (Strings, Numbers, Booleans, ...)
26+
/// - Decodable enumerations
27+
/// - Objects decodable from JSON
2728
/// - Arrays of primitive values
28-
/// - Arrays of enum cases with a primitive `RawValue`
29-
/// - Arrays of objects.
29+
/// - Arrays of enumeration cases
30+
/// - Arrays of objects
31+
/// - Native dictionaries
3032
///
3133

3234
public final class JSVariable<T>: JSExpression where T: Decodable {
33-
3435
public typealias ReturnType = T
3536

3637
/// The path to the variable, relative to the current `this` object tree.
@@ -46,7 +47,7 @@ public final class JSVariable<T>: JSExpression where T: Decodable {
4647
///
4748
/// ~~~swift
4849
/// let title = JSVariable<String>("document.title")
49-
/// // equivalent to the JS script `this.document.title;`
50+
/// // equivalent to the JS script: `this.document.title;`
5051
/// ~~~
5152
///
5253

0 commit comments

Comments
 (0)