import { Action , ChangeType , FinalDomElement , Plugin , PluginOptions , registerPlugin } from "../../src" ; export class EchoPlugin implements Plugin < { } > { log_ ? : PluginOptions [ "log" ] ; log ( ... args ) { if ( this . log_ == null ) throw new Error ( `Plugin has no log function` ) ; this . log_ ( `${ this . constructor . name }:` , ... args ) ; } async start ( options ) { if ( options . log == null ) throw new Error ( `Plugin start called without log` ) ; this . log_ = options . log ; this . log ( "start" ) ; } async observe ( _oldDom , dom ) { this . log ( "observe" , dom ) ; return { } ; } analyze ( _oldDom , dom , _obs ) { this . log ( "analyze" , dom ) ; return [ { act : ( ) => this . doAction ( "action1" ) , type : ChangeType . create , detail : "echo action1 Action" , changes : [ { type : ChangeType . create , element : dom as FinalDomElement , detail : "echo action1 Change" } ] } , { act : ( ) => this . doAction ( "action2" ) , type : ChangeType . create , detail : "echo action2 Action" , changes : [ { type : ChangeType . create , element : dom as FinalDomElement , detail : "echo action2 Change" } ] } , ] ; } async finish ( ) { this . log ( "finish" ) ; } async doAction ( msg ) { this . log ( msg ) ; } } export function create ( ) { return new EchoPlugin ( ) ; } registerPlugin ( { name : "echo" , module , create , } ) ;