1
0
Fork 0
mirror of https://github.com/kbparagua/paloma synced 2023-03-27 23:21:17 -04:00

Remove Execution Chains

This commit is contained in:
kbparagua 2013-11-13 22:00:58 +08:00
parent 7138f2430b
commit 38072ca1a6
3 changed files with 11 additions and 24 deletions

View file

@ -13,16 +13,12 @@
// Remove any callback details if any // Remove any callback details if any
$('.js-paloma-hook[data-id!=' + <%= id %> + ']').remove(); $('.js-paloma-hook[data-id!=' + <%= id %> + ']').remove();
var requests = <%= requests.to_json.html_safe %>; var request = <%= request.to_json.html_safe %>;
for (var i = 0, len = requests.length; i < len; i++){
var request = requests[i];
Paloma.engine.request(request['resource'],
request['action'],
request['params']);
}
Paloma.engine.request(
request['resource'],
request['action'],
request['params']);
$(document).ready(function(){ Paloma.engine.start(); }); $(document).ready(function(){ Paloma.engine.start(); });

View file

@ -24,8 +24,8 @@ module Paloma
# Use on controllers to pass variables to Paloma controller. # Use on controllers to pass variables to Paloma controller.
# #
def js params = {} def js params = {}
return session[:paloma_requests].pop if !params return @__paloma_request = nil if !params
session[:paloma_requests].last[:params] = params @__paloma_request[:params] = params
end end
@ -37,11 +37,7 @@ module Paloma
def track_paloma_request def track_paloma_request
resource = controller_path.split('/').map(&:titleize).join('/').gsub(' ', '') resource = controller_path.split('/').map(&:titleize).join('/').gsub(' ', '')
paloma_request = {:resource => resource, @__paloma_request = {:resource => resource, :action => self.action_name}
:action => self.action_name}
session[:paloma_requests] ||= []
session[:paloma_requests].push paloma_request
end end
@ -53,11 +49,11 @@ module Paloma
# will execute the tracked Paloma requests. # will execute the tracked Paloma requests.
# #
def append_paloma_hook def append_paloma_hook
return true if session[:paloma_requests].empty? return true if @__paloma_request.nil?
hook = view_context.render( hook = view_context.render(
:partial => 'paloma/hook', :partial => 'paloma/hook',
:locals => {:requests => session[:paloma_requests]}) :locals => {:request => @__paloma_request})
before_body_end_index = response_body[0].rindex('</body>') before_body_end_index = response_body[0].rindex('</body>')
@ -72,7 +68,7 @@ module Paloma
response.body += hook response.body += hook
end end
session[:paloma_requests] = nil @__paloma_request = nil
end end
end end

View file

@ -16,11 +16,6 @@ feature 'executing Paloma controller', :js => true do
context 'coming from a redirect' do context 'coming from a redirect' do
before { visit foo_index_path } before { visit foo_index_path }
it 'executes first the Paloma action of the first Rails action' do
first = page.evaluate_script 'window.called[0]'
expect(first).to eq 'MyFoo#index'
end
it 'executes next the Paloma action of the last Rails action' do it 'executes next the Paloma action of the last Rails action' do
last = page.evaluate_script 'window.called.pop()' last = page.evaluate_script 'window.called.pop()'
expect(last).to eq 'Main#index' expect(last).to eq 'Main#index'