sugarlabs / sugar-web

Components for Sugar web activities
Apache License 2.0
13 stars 32 forks source link

Add activity.write and save to datastore before stop #63

Closed manuq closed 11 years ago

manuq commented 11 years ago

Activities that want to store something should override activity.write . It is called before the activity stop.

manuq commented 11 years ago

Here is how GTD activity is using it:

https://github.com/manuq/gtd-activity/blob/master/js/activity.js#L17

dnarvaez commented 11 years ago

I wonder if it would be better to have Activity provide only a "session" API, for example start/activate/deactivate/stop and then let activities decide when they want to save to datastore. It feels more flexible to me.

manuq commented 11 years ago

Yeah I don't like very much the implementation. In GTK is easier because activities are made as classes, which inherit Activity. And as an activity developer you override the methods read() and write().

In the Sugar way, data storage is transparent to the user. There is no 'save' button. GTK activities persist data when they go to the background or when they stop. They call write(). I think we should aim to do the same approach in web activities. But I don't like my current implementation.

So a session API might be better. How would you implement it?

dnarvaez commented 11 years ago

As discussed in irc, I think we can do it in apisocket. We are already associating socket to activity, we just need to watch activity lifecycle and forward notifications to js.

manuq commented 11 years ago

Yeah, I will try. I did this little diagram, with the datastore interactions marked. Maybe we can do it with JS events. web-lifecycle

dnarvaez commented 11 years ago

Looks perfect to me.