File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ const getInitialState = () => ({
5
5
errors : [ ] ,
6
6
data : undefined ,
7
7
error : undefined ,
8
- updatedAt : undefined
8
+ updatedAt : undefined ,
9
+ lastPostAt : undefined
9
10
} )
10
11
11
12
const uninitialized = ( ) => {
@@ -35,6 +36,11 @@ class WebWorker extends React.Component {
35
36
)
36
37
}
37
38
39
+ postMessage = data => {
40
+ const { postMessage = uninitialized } = this . worker || { }
41
+ this . setState ( { lastPostAt : new Date ( ) } , ( ) => postMessage . call ( this . worker , data ) )
42
+ }
43
+
38
44
componentDidMount ( ) {
39
45
this . worker = new window . Worker ( this . props . path )
40
46
this . worker . onmessage = this . onMessage
@@ -50,10 +56,9 @@ class WebWorker extends React.Component {
50
56
51
57
render ( ) {
52
58
const { children } = this . props
53
- const { postMessage = uninitialized } = this . worker || { }
54
59
const renderProps = {
55
60
...this . state ,
56
- postMessage : ( ... args ) => postMessage . call ( this . worker , ... args )
61
+ postMessage : this . postMessage
57
62
}
58
63
59
64
if ( typeof children === "function" ) {
You can’t perform that action at this time.
0 commit comments