You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The returned function also accepts a second object argument, that may contain temporary variables.
44
-
Temporary variables are added to the context object while the code is executing and removed after.
44
+
Temporary variables are added to the context object while the code is executing.
45
45
They are favored over the permanent context variables.
46
46
47
47
```js
@@ -51,9 +51,58 @@ const temporary = {prop1: 2}
51
51
constsum=code(context, temporary) // sum is 4, context is still {prop1: 1, prop2: 2}
52
52
```
53
53
54
-
### compiler.compileExpression(String)
54
+
#### Limiters
55
+
56
+
Limiters are functions, which can defer or block code execution. Some popular limiters are debounce and throttle for example. Limiters can be registered by name with `compiler.limiter(name, function)` and used at the end of the code with the `&` symbol.
code(context) // prints 'Hello World' to the console after a second
65
+
```
66
+
67
+
Limiters accept a context object, which can be used to share a context between executions of the code. It makes the creation of rate limiters - like throttle and debounce - straightforward.
68
+
69
+
```js
70
+
compiler.limiter('debounce', debounce)
71
+
72
+
functiondebounce (next, context) {
73
+
clearTimeout(context.timer)
74
+
context.timer=setTimeout(next, 200)
75
+
}
76
+
```
77
+
78
+
After the context argument limiters accept any number of custom arguments. These can be passed after the limiter name in the code, separated by spaces.
result =expression(context) // result is 'item name'
77
126
```
78
127
79
-
###compiler.expose(String, String, String, ...)
128
+
#### Filters
80
129
81
-
Use this method to expose globals to the compiler. Non of the globals are exposed by default.
130
+
Filters are functions, which can filter and modify expression result. Some popular filters are upperCase and trim for example. Filters can be registered by name with `compiler.filter(name, function)` and used at the end of the expression with the `|` symbol.
0 commit comments