@ -39,7 +39,6 @@ function handleMessage(ev) {
const sendOk = ( ) => sendReply ( { action : "cmdOk" } ) ;
const sendError = ( message , stack ) => sendReply ( { action : "cmdError" , message , stack } )
parent . postMessage ( { action : "test" } , ev . origin ) ;
if ( action == "eval" ) {
let { script } = ev . data . args ;
@ -47,7 +46,7 @@ function handleMessage(ev) {
eval ( script ) ;
sendOk ( ) ;
} catch ( e ) {
sendError ( e . message , e . stack )
sendError ( e . message , e . stack ) ;
}
}
@ -56,10 +55,12 @@ function handleMessage(ev) {
if ( ! window . component ) {
// TODO can this happen?
console . error ( ` no component to bind to ` ) ;
console . warn ( 'no component to bind to' ) ;
sendOk ( ) ;
return ;
}
try {
props . forEach ( prop => {
// TODO should there be a public API for binding?
// e.g. `component.$watch(prop, handler)`?
@ -68,17 +69,28 @@ function handleMessage(ev) {
sendMessage ( { action : "prop_update" , args : { prop , value } } )
} ;
} ) ;
sendOk ( ) ;
} catch ( e ) {
sendError ( e . message , e . stack ) ;
}
}
if ( action == "set_prop" ) {
try {
if ( ! window . component ) {
return ;
}
let { prop , value } = ev . data . args ;
component [ prop ] = value ;
sendOk ( ) ;
} catch ( e ) {
sendError ( e . message , e . stack ) ;
}
}
if ( action == "catch_clicks" ) {
try {
let topOrigin = ev . origin ;
document . body . addEventListener ( 'click' , event => {
if ( event . which !== 1 ) return ;
@ -104,6 +116,10 @@ function handleMessage(ev) {
window . open ( el . href , '_blank' ) ;
} ) ;
sendOk ( ) ;
} catch ( e ) {
sendError ( e . message , e . stack ) ;
}
}