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 = () => ({
55 errors : [ ] ,
66 data : undefined ,
77 error : undefined ,
8- updatedAt : undefined
8+ updatedAt : undefined ,
9+ lastPostAt : undefined
910} )
1011
1112const uninitialized = ( ) => {
@@ -35,6 +36,11 @@ class WebWorker extends React.Component {
3536 )
3637 }
3738
39+ postMessage = data => {
40+ const { postMessage = uninitialized } = this . worker || { }
41+ this . setState ( { lastPostAt : new Date ( ) } , ( ) => postMessage . call ( this . worker , data ) )
42+ }
43+
3844 componentDidMount ( ) {
3945 this . worker = new window . Worker ( this . props . path )
4046 this . worker . onmessage = this . onMessage
@@ -50,10 +56,9 @@ class WebWorker extends React.Component {
5056
5157 render ( ) {
5258 const { children } = this . props
53- const { postMessage = uninitialized } = this . worker || { }
5459 const renderProps = {
5560 ...this . state ,
56- postMessage : ( ... args ) => postMessage . call ( this . worker , ... args )
61+ postMessage : this . postMessage
5762 }
5863
5964 if ( typeof children === "function" ) {
You can’t perform that action at this time.
0 commit comments