import * as C from '@france-ioi/persistent-c' ; import { StepperContext } from "../api" ; import { Bundle } from "../../linker" ; import { App } from "../../index" ; import produce from "immer" ; export default function ( bundle ) { bundle . defer ( function ( { stepperApi } ) { stepperApi . onEffect ( 'control' , function * controlHandler ( stepperContext , control ) { stepperContext . state . programState = produce ( stepperContext . state . programState , ( draft ) => { C . effects . doControl ( draft , control ) ; } ) ; } ) ; stepperApi . onEffect ( 'result' , function * resultHandler ( stepperContext , result ) { stepperContext . state . programState = produce ( stepperContext . state . programState , ( draft ) => { C . effects . doResult ( draft , result ) ; } ) ; } ) ; stepperApi . onEffect ( 'load' , function * loadHandler ( stepperContext , ref ) { stepperContext . state . programState = produce ( stepperContext . state . programState , ( draft ) => { C . effects . doLoad ( draft , ref ) ; } ) ; } ) ; stepperApi . onEffect ( 'store' , function * storeHandler ( stepperContext , ref , value ) { stepperContext . state . programState = produce ( stepperContext . state . programState , ( draft ) => { C . effects . doStore ( draft , ref , value ) ; } ) ; } ) ; stepperApi . onEffect ( 'enter' , function * enterHandler ( stepperContext , blockNode ) { stepperContext . state . programState = produce ( stepperContext . state . programState , ( draft ) => { C . effects . doEnter ( draft , blockNode ) ; draft . scope . directives = blockNode [ 1 ] . directives || [ ] ; } ) ; } ) ; stepperApi . onEffect ( 'leave' , function * leaveHandler ( stepperContext , blockNode ) { stepperContext . state . programState = produce ( stepperContext . state . programState , ( draft ) => { C . effects . doLeave ( draft , blockNode ) ; } ) ; } ) ; stepperApi . onEffect ( 'call' , function * callHandler ( stepperContext , cont , values ) { stepperContext . state . programState = produce ( stepperContext . state . programState , ( draft ) => { C . effects . doCall ( draft , cont , values ) ; const bodyNode = values [ 0 ] . decl ; draft . scope . directives = bodyNode [ 1 ] . directives || [ ] ; } ) ; } ) ; stepperApi . onEffect ( 'return' , function * returnHandler ( stepperContext , result ) { stepperContext . state . programState = produce ( stepperContext . state . programState , ( draft ) => { C . effects . doReturn ( draft , result ) ; } ) ; } ) ; stepperApi . onEffect ( 'vardecl' , function * vardeclHandler ( stepperContext , name , type , init ) { stepperContext . state . programState = produce ( stepperContext . state . programState , ( draft ) => { C . effects . doVardecl ( draft , name , type , init ) ; } ) ; } ) ; } ) ; } ;