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
Copy file name to clipboardExpand all lines: api.md
+7-8Lines changed: 7 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -191,11 +191,8 @@ const MergingAction = state => [
191
191
<aname="module_fx.exports.Random"></a>
192
192
193
193
### fx.exports.Random(props)
194
-
Describes an effect that will call an action with a [randomly generated number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) within a range.
195
-
If provided the range will be `[min, max)` or else the default range is `[0, 1)`. The random number will be provided as the action `data`.
196
-
197
-
Use [`Math.floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor) if you want a random integer instead of a floating-point number.
198
-
Remember the range will be `max` exclusive, so use your largest desired int + 1.
194
+
Describes an effect that will call an action with one or more randomly generated value(s).
195
+
If provided the range for [random numeric values](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) will be `[min, max)` or else the default range is `[0, 1)`. Also `bool`eans, `int`egers, and arrays of `values` are supported. The random value will be provided as the action `data`.
199
196
200
197
**Kind**: static method of [<code>fx</code>](#module_fx)
201
198
@@ -205,6 +202,9 @@ Remember the range will be `max` exclusive, so use your largest desired int + 1.
205
202
| props.action | <code>\*</code> | action to call with the random number result |
206
203
| props.min | <code>number</code> | minimum random number to generate |
207
204
| props.max | <code>number</code> | maximum random number to generate |
205
+
| props.int | <code>boolean</code> | round number to nearest integer |
206
+
| props.bool | <code>boolean</code> | generate a boolean instead of a number (ignores numeric options) |
207
+
| props.values | <code>Array.<object></code> | generate an array of values (ignores other options, each object accepts same props as the root) |
208
208
209
209
**Example**
210
210
```js
@@ -214,10 +214,9 @@ const RollDie = state => [
214
214
state,
215
215
Random({
216
216
min:1,
217
-
// We use the max of 7 to include all values of 6.x
* Describes an effect that will call an action with a [randomly generated number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) within a range.
8
-
* If provided the range will be `[min, max)` or else the default range is `[0, 1)`. The random number will be provided as the action `data`.
9
-
*
10
-
* Use [`Math.floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor) if you want a random integer instead of a floating-point number.
11
-
* Remember the range will be `max` exclusive, so use your largest desired int + 1.
28
+
* Describes an effect that will call an action with one or more randomly generated value(s).
29
+
* If provided the range for [random numeric values](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) will be `[min, max)` or else the default range is `[0, 1)`. Also `bool`eans, `int`egers, and arrays of `values` are supported. The random value will be provided as the action `data`.
12
30
*
13
31
* @memberof module:fx
14
32
* @param {object} props
15
33
* @param {*} props.action - action to call with the random number result
16
34
* @param {number} props.min - minimum random number to generate
17
35
* @param {number} props.max - maximum random number to generate
36
+
* @param {boolean} props.int - round number to nearest integer
37
+
* @param {boolean} props.bool - generate a boolean instead of a number (ignores numeric options)
38
+
* @param {object[]} props.values - generate an array of values (ignores other options, each object accepts same props as the root)
18
39
* @example
19
40
* import { Random } from "hyperapp-fx"
20
41
*
21
42
* const RollDie = state => [
22
43
* state,
23
44
* Random({
24
45
* min: 1,
25
-
* // We use the max of 7 to include all values of 6.x
26
46
* max: 7,
27
-
* action: (_, randomNumber) => {
28
-
* const roll = Math.floor(randomNumber)
47
+
* int: true,
48
+
* action: (_, roll) => {
29
49
* // roll will be an int from 1-6
30
50
*
31
51
* // return new state using roll
@@ -34,12 +54,5 @@ function randomEffect(props, dispatch) {
0 commit comments