Trigger doesn't seem to trigger an event.

88 views
Skip to first unread message

Tom Streller

unread,
May 14, 2012, 11:57:28 AM5/14/12
to sam...@googlegroups.com
Hello,

I have a problem with the event handling. I have this code: https://gist.github.com/668372edb9d54339fbc3

As you can see, in line 31, I bind the relog function to the event 'relog'. However, when I try to trigger the event, it doesn't seem to work - the relog function is not called. I trigger the event in lines 48, 59 and 61. The AJAX request comes through, I get it on the developer tools and the server logs, but the relog function is not called (breakpoint never reached).

Sammy version is 0.7.1 from the git, not edge.

Am I using it wrong?

Andriy Zhdanov

unread,
May 15, 2012, 5:40:46 AM5/15/12
to Sammy.js
Hi Tom,

It's me again :) I seem have been doing the same feature, I don't
remember if triggering did not work for me too, but I ended with
session store instead, and update it in login/logout. Well, this is
not perfect also. But you may check this approach:
http://code.google.com/p/yogamamadvd/source/browse/trunk/catalog/view/javascript/app/account.js

I may check why triggering does not work later and let you know, if i
have a chance.

Thank you.

Tom Streller

unread,
May 15, 2012, 5:58:12 AM5/15/12
to sam...@googlegroups.com
Like me, you figured it out with listening to the "run" event ;)

I just have a question: How do you ensure the authenticy of the user? How can the server be sure that the user doing the next request is the ine who just logged in?

2012/5/15 Andriy Zhdanov <azhd...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Sammy.js" group.
To post to this group, send email to sam...@googlegroups.com.
To unsubscribe from this group, send email to sammyjs+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sammyjs?hl=en.


Andriy Zhdanov

unread,
May 15, 2012, 5:14:45 PM5/15/12
to Sammy.js
Well, I think it's more complicated, I listen to 'location-changed'
event, and fire it also, can't understand 'why' now.

I've also just tried firing other event from login/logout, it seem to
work too.

Regarding the authenticity, in my case, server has it's own
authentication session (tracked within cookie), I'm just trying to
keep in sync client state using 'store'. When it's really important
that server session is valid, I call account:connected with callback,
when it's not critical, it just check the 'store.

Frankly speaking it's not working very well. For some reason store is
cleared on second attempt within logout, may be I get more than one
'app' instances.

If you want to play with it, but it does not use this 'welcome' text
anymore, see http://yogastudio.cz/eshop/index.php/checkout/shipment,
it's in Russian, but you may figure out what to do :), login/password
is te...@example.com/password, then to logout type
http://yogastudio.cz/eshop/index.php/account/account in address bar,
and check first page again, it should prompt to login but it does not,
while doing logout again helps this time. Weird :-/

Thank you.

On May 15, 11:58 am, Tom Streller <lambdad...@googlemail.com> wrote:
> Like me, you figured it out with listening to the "run" event ;)
>
> I just have a question: How do you ensure the authenticy of the user? How
> can the server be sure that the user doing the next request is the ine who
> just logged in?
>
> 2012/5/15 Andriy Zhdanov <azhda...@gmail.com>
>
>
>
>
>
>
>
> > Hi Tom,
>
> > It's me again :) I seem have been doing the same feature, I don't
> > remember if triggering did not work for me too, but I ended with
> > session store instead, and update it in login/logout. Well, this is
> > not perfect also. But you may check this approach:
>
> >http://code.google.com/p/yogamamadvd/source/browse/trunk/catalog/view...

alexandroid

unread,
May 16, 2012, 3:14:22 AM5/16/12
to Sammy.js
Hi Tom,

Have you tried stepping through Sammy to see why it does not trigger
relog?

It may be a long shot but wonder if it is a bug in the Sammy's bind
function in case when only 2 arguments are used with bind:

bind: function(name, data, callback) {
var app = this;
// build the callback
// if the arity is 2, callback is the second argument
if (typeof callback == 'undefined') { callback = data; } <--
data is not cleared here
var listener_callback = function() {
// pull off the context from the arguments to the callback
var e, context, data;
e = arguments[0];
data = arguments[1];
if (data && data.context) { <-- but used here
context = data.context;
delete data.context;
} else {
context = new app.context_prototype(app, 'bind', e.type,
data, e.target); <-- and here
}
e.cleaned_type = e.type.replace(app.eventNamespace(), '');
callback.apply(context, [e, data]);
};

Thanks,
Alex

On May 15, 2:40 am, Andriy Zhdanov <azhda...@gmail.com> wrote:
> Hi Tom,
>
> It's me again :) I seem have been doing the same feature, I don't
> remember if triggering did not work for me too, but I ended with
> session store instead, and update it in login/logout. Well, this is
> not perfect also. But you may check this approach:http://code.google.com/p/yogamamadvd/source/browse/trunk/catalog/view...

Tom Streller

unread,
May 16, 2012, 4:05:14 AM5/16/12
to sam...@googlegroups.com
I'd find that very strange, because the examples shown on the sammy docs always have just two parameters on bind.

2012/5/16 alexandroid <kamo...@gmail.com>
Reply all
Reply to author
Forward
0 new messages