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

- old
+ new

@@ -181,20 +181,34 @@ #Switch the actions, reset embeds, and call on_entry 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} + //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(); + 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. 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]); <% if @debug %> var vp = embeds[i][j]+1; @@ -221,20 +235,22 @@ //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} //'choose_action' pseudo-action will be sent as 'null' as it's the initial state if (old_action === "choose_action") { old_action = null; } //Send off event for action change main_q.push([3, "if_event", __base__, "action", { from: old_action, to: "#{action_name}" }]); + } out.puts res elsif l =~ /Push/ l.strip! l.gsub!(/Push\(/, "") @@ -587,10 +603,10 @@ #Call the macro in our context @current_action = name self.instance_eval(&macro) @current_action = nil else - raise "No macro found named: #{method}" + raise "No macro found named: #{method} for controller #{@controller.name} in action #{@name}" end end end class UserCompilerController