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
@@ -115,7 +117,7 @@ Describes an effect that will add an entry to the browsers navigation [`history`
115
117
116
118
**Example**
117
119
```js
118
-
import { Console } from"hyperapp-fx"
120
+
import { HistoryPush } from"hyperapp-fx"
119
121
120
122
exportconstUpdateHistory=state=> [
121
123
state,
@@ -142,7 +144,7 @@ Describes an effect that will replace the browsers current [`history`](https://d
142
144
143
145
**Example**
144
146
```js
145
-
import { Console } from"hyperapp-fx"
147
+
import { HistoryReplace } from"hyperapp-fx"
146
148
147
149
exportconstInitialiseHistory=state=> [
148
150
state,
@@ -355,17 +357,100 @@ const ThrottledAction = state => [
355
357
})
356
358
]
357
359
```
360
+
<aname="module_fx.exports.Now"></a>
361
+
362
+
### fx.exports.Now(props)
363
+
Describes an effect that provides the current timestamp (using [`performance.now`](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now)) or current date (using [`new Date()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Syntax)). The timestamp/date will be provided as the action `data`.
364
+
365
+
**Kind**: static method of [<code>fx</code>](#module_fx)
366
+
367
+
| Param | Type | Description |
368
+
| --- | --- | --- |
369
+
| props | <code>object</code> ||
370
+
| props.asDate | <code>boolean</code> | use a Date object instead of a timestamp |
371
+
| props.action | <code>\*</code> | action to call with the timestamp/date |
372
+
373
+
**Example**
374
+
```js
375
+
import { Now } from"hyperapp-fx"
376
+
377
+
constNowAction=state=> [
378
+
state,
379
+
Now({
380
+
asDate:true,
381
+
action(currentDate) {
382
+
}
383
+
})
384
+
]
385
+
```
386
+
<aname="module_fx.exports.Delay"></a>
387
+
388
+
### fx.exports.Delay(props)
389
+
Describes an effect that provides a timestamp (using [`performance.now`](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now)) or date (using [`new Date()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Syntax)) after a delay. The timestamp/date will be provided as the action `data`.
390
+
391
+
**Kind**: static method of [<code>fx</code>](#module_fx)
392
+
393
+
| Param | Type | Description |
394
+
| --- | --- | --- |
395
+
| props | <code>object</code> ||
396
+
| props.wait | <code>number</code> | delay to wait before calling action |
397
+
| props.asDate | <code>boolean</code> | use a Date object instead of a timestamp |
398
+
| props.action | <code>\*</code> | action to call with the timestamp/date |
Describes an effect that will open a [`WebSocket`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket) connection for a given URL (and optional protocols) and send a message reusing existing connections.
430
+
431
+
**Kind**: static method of [<code>subs</code>](#module_subs)
432
+
433
+
| Param | Type | Description |
434
+
| --- | --- | --- |
435
+
| props | <code>object</code> ||
436
+
| props.url | <code>string</code> | The URL to which to connect; this should be the URL to which the WebSocket server will respond |
437
+
| props.protocols | <code>string</code> \| <code>Array.<string></code> | Either a single protocol string or an array of protocol strings. These strings are used to indicate sub-protocols, so that a single server can implement multiple WebSocket sub-protocols (for example, you might want one server to be able to handle different types of interactions depending on the specified `protocol`). If you don't specify a protocol string, an empty string is assumed. |
438
+
| props.data | <code>\*</code> | data to send once connected |
439
+
440
+
**Example**
441
+
```js
442
+
import { WebSocketSend } from"hyperapp-fx"
443
+
444
+
constSendAction=state=> [
445
+
state,
446
+
WebSocketSend({
447
+
url:"wss://example.com",
448
+
data:JSON.stringify({
449
+
sendThisData:"on connecting"
450
+
})
451
+
})
452
+
]
453
+
```
369
454
<aname="module_subs.exports.Animation"></a>
370
455
371
456
### subs.exports.Animation(action)
@@ -421,13 +506,16 @@ Describes an effect that will call an action whenever a user navigates through t
421
506
422
507
**Example**
423
508
```js
509
+
import { h, app } from"hyperapp"
424
510
import { HistoryPop } from"hyperapp-fx"
425
511
426
512
app({
427
-
init: { page:1 },
428
-
view:state=><App page={state.page} />,
429
-
container:document.body,
430
-
subscriptions:state=> [HistoryPop({ action: (state, event) =>event.state|| state })]
513
+
init: { page:1 },
514
+
view:state=><App page={state.page} />,
515
+
container:document.body,
516
+
subscriptions:state=> [
517
+
HistoryPop({ action: (state, event) =>event.state|| state })
518
+
]
431
519
})
432
520
```
433
521
<aname="module_subs.exports.Keyboard"></a>
@@ -458,26 +546,24 @@ const KeySub = Keyboard({
458
546
}
459
547
})
460
548
```
461
-
<aname="module_subs.exports.Time"></a>
549
+
<aname="module_subs.exports.Interval"></a>
462
550
463
-
### subs.exports.Time(props)
464
-
Describes an effect that can provide timestamps to actions using [`performance.now`](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now) or dates using the [`new Date()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Syntax) API. The action can be fired now, after a delay, or at a regular interval. The timestamp/date will be provided as the action `data`.
551
+
### subs.exports.Interval(props)
552
+
Describes an effect that provides a timestamp (using [`performance.now`](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now)) or date (using [`new Date()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Syntax)) at a regular interval. The timestamp/date will be provided as the action `data`.
465
553
466
554
**Kind**: static method of [<code>subs</code>](#module_subs)
467
555
468
556
| Param | Type | Description |
469
557
| --- | --- | --- |
470
558
| props | <code>object</code> ||
471
-
| props.now | <code>boolean</code> | get the current time immediately |
472
-
| props.after | <code>number</code> | get the time after a delay |
473
-
| props.every | <code>number</code> | get the time repeatedly after waiting a set interval |
474
559
| props.asDate | <code>boolean</code> | use a Date object instead of a timestamp |
475
-
| props.action | <code>\*</code> | action to call with the time |
560
+
| props.every | <code>number</code> | get the time repeatedly after waiting a set interval |
561
+
| props.action | <code>\*</code> | action to call with the timestamp/date |
Describes an effect that will open a [`WebSocket`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket) connection for a given URL and optional protocols. A message may be sent to the server on connection and messages to the client may be listened for. Connections will remain open until the last subscription for that URL are cancelled.
595
+
### subs.exports.WebSocketListen(props)
596
+
Describes an effect that will open a [`WebSocket`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket) connection for a given URL and optional protocols. Connections will remain open until the last subscription for that URL are cancelled.
512
597
513
598
**Kind**: static method of [<code>subs</code>](#module_subs)
514
599
@@ -517,19 +602,15 @@ Describes an effect that will open a [`WebSocket`](https://developer.mozilla.org
517
602
| props | <code>object</code> ||
518
603
| props.url | <code>string</code> | The URL to which to connect; this should be the URL to which the WebSocket server will respond |
519
604
| props.protocols | <code>string</code> \| <code>Array.<string></code> | Either a single protocol string or an array of protocol strings. These strings are used to indicate sub-protocols, so that a single server can implement multiple WebSocket sub-protocols (for example, you might want one server to be able to handle different types of interactions depending on the specified `protocol`). If you don't specify a protocol string, an empty string is assumed. |
520
-
| props.send | <code>\*</code> | data to send once connected |
521
-
| props.listen | <code>\*</code> | action to call with new incoming messages |
605
+
| props.action | <code>\*</code> | action to call with new incoming messages |
522
606
| props.error | <code>\*</code> | action to call if an error occurs |
* Describes an effect that provides the current timestamp (using [`performance.now`](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now)) or current date (using [`new Date()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Syntax)). The timestamp/date will be provided as the action `data`.
13
+
*
14
+
* @memberof module:fx
15
+
* @param {object} props
16
+
* @param {boolean} props.asDate - use a Date object instead of a timestamp
17
+
* @param {*} props.action - action to call with the timestamp/date
18
+
* @example
19
+
* import { Now } from "hyperapp-fx"
20
+
*
21
+
* const NowAction = state => [
22
+
* state,
23
+
* Now({
24
+
* asDate: true,
25
+
* action(currentDate) {
26
+
* }
27
+
* })
28
+
* ]
29
+
*/
30
+
exportfunctionNow(props){
31
+
return[nowEffect,props]
32
+
}
33
+
34
+
/**
35
+
* Describes an effect that provides a timestamp (using [`performance.now`](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now)) or date (using [`new Date()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Syntax)) after a delay. The timestamp/date will be provided as the action `data`.
36
+
*
37
+
* @memberof module:fx
38
+
* @param {object} props
39
+
* @param {number} props.wait - delay to wait before calling action
40
+
* @param {boolean} props.asDate - use a Date object instead of a timestamp
41
+
* @param {*} props.action - action to call with the timestamp/date
* Describes an effect that will open a [`WebSocket`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket) connection for a given URL (and optional protocols) and send a message reusing existing connections.
20
+
*
21
+
* @memberof module:subs
22
+
* @param {object} props
23
+
* @param {string} props.url - The URL to which to connect; this should be the URL to which the WebSocket server will respond
24
+
* @param {string | string[]} props.protocols - Either a single protocol string or an array of protocol strings. These strings are used to indicate sub-protocols, so that a single server can implement multiple WebSocket sub-protocols (for example, you might want one server to be able to handle different types of interactions depending on the specified `protocol`). If you don't specify a protocol string, an empty string is assumed.
25
+
* @param {*} props.data - data to send once connected
0 commit comments