@@ -2,6 +2,7 @@ import * as actions from "./actions";
22
33import { repoSlice } from "../store" ;
44import Stomp from "stompjs" ;
5+ import pod from "../reducers/pod" ;
56
67function getReexports ( { id, pods } ) {
78 // Get the reexports available for the deck id. Those are from this deck's subdecks
@@ -218,20 +219,36 @@ function getChildExports({ id, pods }) {
218219 return res ;
219220}
220221
222+ function getUtilExports ( { id, pods } ) {
223+ let res = { } ;
224+ let utilIds = getUtilIds ( { id, pods } ) ;
225+ for ( let deck of utilIds . map ( ( id ) => pods [ id ] ) ) {
226+ // FIXME these are identical to getChildExports
227+ res [ deck . ns ] = [ ] . concat (
228+ ...deck . children
229+ . filter ( ( { id } ) => pods [ id ] . type !== "DECK" )
230+ . map ( ( { id } ) => pods [ id ] )
231+ . map ( ( pod ) => Object . keys ( pod . exports ) )
232+ ) ;
233+ for ( let deckpod of deck . children
234+ . filter ( ( { id } ) => pods [ id ] . type !== "DECK" )
235+ . map ( ( { id } ) => pods [ id ] ) ) {
236+ for ( let [ name , id ] of Object . entries ( deckpod . reexports ) ) {
237+ if ( ! res [ pods [ id ] . ns ] ) {
238+ res [ pods [ id ] . ns ] = [ ] ;
239+ }
240+ res [ pods [ id ] . ns ] . push ( name ) ;
241+ }
242+ }
243+ }
244+ return res ;
245+ }
246+
221247function powerRun_python ( { id, storeAPI, socket } ) {
222248 let pods = storeAPI . getState ( ) . repo . pods ;
223249 let pod = pods [ id ] ;
224250 // python powerrun
225251 // 1. create the module
226- let nses = getUtilNs ( { id, pods } ) ;
227- const child_deck_nses = pods [ id ] . children
228- . filter ( ( { id } ) => pods [ id ] . type === "DECK" && ! pods [ id ] . thundar )
229- . map ( ( { id, type } ) => pods [ id ] . ns ) ;
230- nses = nses . concat ( child_deck_nses ) ;
231- // if it is a test desk, get parent
232- if ( pod . thundar ) {
233- nses . push ( pods [ pod . parent ] . ns ) ;
234- }
235252
236253 // for python, we need to introduce the mapping of each exported names
237254 // 0. [X] so, loop through the child decks, and if there are exported names, evaluate it
@@ -243,7 +260,10 @@ function powerRun_python({ id, storeAPI, socket }) {
243260 // if that's a new reexport, add to parent as well and do the resolve and evaluation
244261 // 3. [ ] delete a function. Just delete the parent's def? Not sure.
245262
246- let allexports = getChildExports ( { id, pods } ) ;
263+ let childexports = getChildExports ( { id, pods } ) ;
264+ let utilexports = getUtilExports ( { id, pods } ) ;
265+ // FIXME would childexports and utilexports overlap?
266+ let allexports = Object . assign ( { } , childexports , utilexports ) ;
247267 let code = Object . keys ( allexports )
248268 . map ( ( ns ) =>
249269 allexports [ ns ]
@@ -314,6 +334,26 @@ function handlePowerRun({ id, doEval, storeAPI, socket }) {
314334 }
315335}
316336
337+ function codeForReEvalDeck ( { deck, pods, name, ns } ) {
338+ // this deck is a utility deck. Evaluate a re-define of name from ns in all the scope
339+ let parent = pods [ deck . parent ] ;
340+ let res = "" ;
341+ res += `
342+ CODEPOD_EVAL("""${ name } = CODEPOD_GETMOD("${ ns } ").__dict__["${ name } "]\n0""", "${ parent . ns } ")
343+ ` ;
344+ function helper ( id ) {
345+ if ( pods [ id ] . type === "DECK" && pods [ id ] . ns !== ns ) {
346+ res += `
347+ CODEPOD_EVAL("""${ name } = CODEPOD_GETMOD("${ ns } ").__dict__["${ name } "]\n0""", "${ pods [ id ] . ns } ")
348+ ` ;
349+ pods [ id ] . children . map ( ( { id, type } ) => helper ( id ) ) ;
350+ }
351+ }
352+ // for all the subdecks
353+ parent . children . map ( ( { id, type } ) => helper ( id ) ) ;
354+ return res ;
355+ }
356+
317357function handleUpdateDef ( { id, storeAPI, socket } ) {
318358 let pods = storeAPI . getState ( ) . repo . pods ;
319359 let pod = pods [ id ] ;
@@ -325,6 +365,17 @@ function handleUpdateDef({ id, storeAPI, socket }) {
325365 code += `
326366CODEPOD_EVAL("""${ name } = CODEPOD_GETMOD("${ pod . ns } ").__dict__["${ name } "]\n0""", "${ parent_deck . ns } ")
327367` ;
368+ if ( pods [ pod . parent ] . utility ) {
369+ // TODO get all scopes and reevaluate
370+ // 1. get parent
371+ // 2. loop
372+ code += codeForReEvalDeck ( {
373+ deck : pods [ pod . parent ] ,
374+ pods,
375+ name,
376+ ns : pod . ns ,
377+ } ) ;
378+ }
328379 console . log ( "==" , name , uses ) ;
329380 if ( uses ) {
330381 for ( let use of uses ) {
@@ -333,11 +384,22 @@ CODEPOD_EVAL("""${name} = CODEPOD_GETMOD("${pod.ns}").__dict__["${name}"]\n0""",
333384 code += `
334385CODEPOD_EVAL("""${ name } = CODEPOD_GETMOD("${ pod . ns } ").__dict__["${ name } "]\n0""", "${ to_deck . ns } ")
335386` ;
387+ if ( pods [ pods [ use ] . parent ] . utility ) {
388+ // TODO get all scopes and re-evaluate
389+ code += codeForReEvalDeck ( {
390+ deck : pods [ pods [ use ] . parent ] ,
391+ pods,
392+ name,
393+ ns : pod . ns ,
394+ } ) ;
395+ }
336396 }
337397 }
338398 }
339399
340- code += `"ok"` ;
400+ code += `
401+ "ok"
402+ ` ;
341403
342404 // console.log("handleUpdateDef code", code);
343405
@@ -374,6 +436,16 @@ function getUtilNs({ id, pods, exclude }) {
374436 return res . concat ( getUtilNs ( { id : pods [ id ] . parent , pods, exclude : id } ) ) ;
375437}
376438
439+ function getUtilIds ( { id, pods, exclude } ) {
440+ // similar to getUtilNs, but return the id of the util deck
441+ if ( ! id ) return [ ] ;
442+ let res = pods [ id ] . children
443+ . filter ( ( { id } ) => id !== exclude && pods [ id ] . utility )
444+ . map ( ( { id, type } ) => id ) ;
445+ // keep to go to parents
446+ return res . concat ( getUtilIds ( { id : pods [ id ] . parent , pods, exclude : id } ) ) ;
447+ }
448+
377449function getExports ( content ) {
378450 // Return exports, reexports, and the rest content
379451 // analyze the content for magic commands
0 commit comments