[Sugar-devel] sugar-web - API for storing data

Manuel Quiñones manuq at laptop.org
Mon Sep 9 15:50:57 EDT 2013


Hi, I'm reliving this topic again

2013/8/16 Daniel Narvaez <dwnarvaez at gmail.com>:
> Hey,
>
> It seems be have two (mostly) independent questions here
>
> - How do we notify an activity of certain global events, being them
> onPause/onStop or onRead/onWrite.
>
> If we want them to be passed in activity.setup() I think we should use an
> object, like {"onSomething": ..., "onSomethingElse":..}. That will allow to
> subscribe only to some of the available events. With two events that would
> probably be overkill but if nothing else I think onStart/onPause/onStop
> should be supported, even if we also have onRead and onWrite. They are
> needed for more than writing to the datastore.
>
> Though, any reason to not use custom DOM events? This seems exactly the use
> case they are designed for.
> http://www.w3.org/TR/DOM-Level-3-Events/#extending_events-Custom_Events

I have sent a PR that connects to shell notifications pause an stop,
and dispatches events:

https://github.com/sugarlabs/sugar-web/pull/83

So activities can do:

        function onStop(event) {
            event.preventDefault();
            saveAndClean(function (error) {
                activity.close();
            });
        }
        window.addEventListener('activityStop', onStop);

I have this working locally with the localStore helper I sent before.
I will push that after this goes in.

A few comments:

I attached the events to the window object.  Another option is a dom
element, but I wonder what is best.  Unfortunatly events work like
that in JS, not for every object.

I used the style "activityStop" for the event name and
"onActivityStop" for the handler.

-- 
.. manuq ..


More information about the Sugar-devel mailing list