[Sugar-devel] sugar-web: env.js questions

Rogelio Mita rogeliomita at activitycentral.com
Fri Nov 22 18:59:36 EST 2013


2013/11/22 Daniel Narvaez <dwnarvaez at gmail.com>

> On 22 November 2013 22:59, Rogelio Mita <rogeliomita at activitycentral.com>wrote:
>
>>
>> About the logic, unfortunately checking window.sugar won't work because
>> we can't assume window.sugar has been already set when getEnvironment is
>> called... the python code you linked might be called after getEnvironment
>> has been called and will erroneously think we are in standalone mode.
>>
>> you are right. I thought for a moment that this fragment is executed to
>> begging before activity.setup(), I'm still in doubt, are you sure about
>> this?
>>
>
> The python code is executed when the page (with all it's resources) has
> been loaded. And I think that can happen either after or before javascript
> activity.setup(), depending on the page, hardware etc.
>
>
>>
>>
>>>
>>> That's why I suggested to check if window.location starts with
>>> activity://. It's a bit ugly but it will always work.
>>>
>>
>> Seems to be a good start, if I understand what you say, it would result
>> there is no need to use callbacks in this method, ie: we can return object
>> environment on sugar environment or null in other case
>>
>
> Nope. getEnvironment will still need to be async because in the
> non-standalone case you need to wait for that python code to be executed.
>

u are right, I missed


> You could have a env.isStandalone() method (no callback) but I have the
> feeling that would make the code using env.getEnvironment more complicated.
>
> Actually I think we should probably have both. Add env.isStandalone() and
> when that's true make getEnvironment() pass {} to the callback. How does
> that sound?
>

This sounds good, in summary, We should have the logic of window.location
in env.isStandalone method and env.getEnvironment still like now but uses
IsStandalone like you say above, this will allow eliminating this
logic here<https://github.com/sugarlabs/sugar-web/blob/master/dictstore.js#L25>
and
here <https://github.com/sugarlabs/sugar-web/blob/master/dictstore.js#L53>(ussing
isStandalone method), and dictstore become free from the
asynchrony, right?


> This is all super-icky and difficult to explain, if you don't understand
> something I can try to clarify further.
>



-- 
Roger

Activity Central <http://activitycentral.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20131122/6cf89089/attachment.html>


More information about the Sugar-devel mailing list