lib/flok/user_compiler.rb in flok-0.0.103 vs lib/flok/user_compiler.rb in flok-0.0.105

- old
+ new

@@ -182,16 +182,16 @@ res = %{ var old_action = __info__.action; __info__.action = "#{action_name}"; var __free_asap = true; - //HOOK_ENTRY[controller_will_goto] #{{"controller_name" => @controller.name, "might_respond_to" => @ctx.might_respond_to, "actions_responds_to" => @ctx.actions_respond_to, "from_action" => @name, "to_action" => action_name}.to_json} + //HOOK_ENTRY[controller_will_goto] #{{"controller_name" => @controller.name, "might_respond_to" => @ctx.might_respond_to, "actions_responds_to" => @ctx.actions_respond_to, "from_action" => @name, "to_action" => action_name, "handling_event_named" => @handling_event_named}.to_json} //If views are configured to not free right away, set up a new stack of views to free //This is usually picked up by the hook GOTO if (__free_asap === false) { - var views_to_free_id = gen_id(); + var views_to_free_id = tels(1); views_to_free[views_to_free_id] = views_to_free[views_to_free_id] || []; } //Remove all views, we don't have to recurse because removal of a view //is supposed to remove *all* view controllers of that tree as well. @@ -235,11 +235,11 @@ //Call on_entry for the new action via the singleton on_entry //located in ctable __info__.cte.actions[__info__.action].on_entry(__base__) - //HOOK_ENTRY[controller_did_goto] #{{"controller_name" => @controller.name, "might_respond_to" => @ctx.might_respond_to, "actions_responds_to" => @ctx.actions_respond_to, "from_action" => @name, "to_action" => action_name}.to_json} + //HOOK_ENTRY[controller_did_goto] #{{"controller_name" => @controller.name, "might_respond_to" => @ctx.might_respond_to, "actions_responds_to" => @ctx.actions_respond_to, "from_action" => @name, "to_action" => action_name, "handling_event_named" => @handling_event_named}.to_json} //'choose_action' pseudo-action will be sent as 'null' as it's the initial state if (old_action === "choose_action") { old_action = null; } @@ -267,20 +267,25 @@ var old_embeds = __info__.embeds; __info__.stack.push({action: old_action, embeds: old_embeds}); __info__.action = "#{action_name}"; + //HOOK_ENTRY[controller_will_push] #{{"controller_name" => @controller.name, "might_respond_to" => @ctx.might_respond_to, "actions_responds_to" => @ctx.actions_respond_to, "from_action" => @name, "to_action" => action_name, "handling_event_named" => @handling_event_named}.to_json} + + //Prep embeds array, embeds[0] refers to the spot bp+2 (bp is vc, bp+1 is main) __info__.embeds = []; for (var i = 1; i < #{@controller.spots.count}; ++i) { __info__.embeds.push([]); } //Call on_entry for the new action via the singleton on_entry //located in ctable __info__.cte.actions[__info__.action].on_entry(__base__) + //HOOK_ENTRY[controller_did_push] #{{"controller_name" => @controller.name, "might_respond_to" => @ctx.might_respond_to, "actions_responds_to" => @ctx.actions_respond_to, "from_action" => @name, "to_action" => action_name, "handling_event_named" => @handling_event_named}.to_json} + //Send off event for action change main_q.push([3, "if_event", __base__, "action", { from: old_action, to: "#{action_name}" }]); @@ -301,28 +306,46 @@ var orig_embeds = restore_info.embeds; //Save the old action //var old_action = __info__.action; + var __free_asap = true; + //HOOK_ENTRY[controller_will_pop] #{{"controller_name" => @controller.name, "might_respond_to" => @ctx.might_respond_to, "actions_responds_to" => @ctx.actions_respond_to, "from_action" => @name, "handling_event_named" => @handling_event_named}.to_json} + + //If views are configured to not free right away, set up a new stack of views to free + //This is usually picked up by the hook GOTO + if (__free_asap === false) { + var views_to_free_id = tels(1); + views_to_free[views_to_free_id] = views_to_free[views_to_free_id] || []; + } + //Restore the action we pushed from __info__.action = orig_action; //Remove all views, we don't have to recurse because removal of a view //is supposed to remove *all* view controllers of that tree as well. var embeds = __info__.embeds; for (var i = 0; i < __info__.embeds.length; ++i) { for (var j = 0; j < __info__.embeds[i].length; ++j) { //Free +1 because that will be the 'main' view - main_q.push([1, "if_free_view", embeds[i][j]+1]); + //Free if 'free_asap' is not set, this is usually configured via the 'goto' hook + if (__free_asap === true) { + main_q.push([1, "if_free_view", embeds[i][j]+1]); + } else { + views_to_free[views_to_free_id].push(embeds[i][j]+1); + } //Call dealloc on the controller tel_deref(embeds[i][j]).cte.__dealloc__(embeds[i][j]); } } //Restore embeds __info__.embeds = orig_embeds; + + //HOOK_ENTRY[controller_did_pop] #{{"controller_name" => @controller.name, "might_respond_to" => @ctx.might_respond_to, "actions_responds_to" => @ctx.actions_respond_to, "from_action" => @name, "handling_event_named" => @handling_event_named}.to_json} + } out.puts res #Request(service_instance_name, ename, info) elsif l =~ /Request/ @@ -578,10 +601,15 @@ #We need this guard because we run a two pass compile on the ons. When 'ons' is accessed, it is assumed that we are now #in the compilation phase and we build all the entries. This is because some macros in the ons source code requires #prior-knowledge of controller-level information like all possible events in all actions for hooks unless @__ons_did_build @__ons_did_build = true - @__ons = @_ons.map{|e| {:name => e[:name], :src => _macro(e[:src])}} + @__ons = @_ons.map do |e| + @handling_event_named = e[:name] + src = _macro(e[:src]) + @handling_event_named = nil + {:name => e[:name], :src => src} + end end @__ons_is_building = false return @__ons end