Baffling Difference between Workspace and Inspector

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Baffling Difference between Workspace and Inspector

Sean P. DeNigris
Administrator
I'm assuming this problem is related to the one I described [1] last time I did a "serious" Amber project.

    `(jQuery getJSON: './suppliers.json') responseJSON` -> DNU
but:
    `(jQuery getJSON: './suppliers.json') inspect` and then `self responseJSON` from that inspector works!

I still can't wrap my head around the difference :/

[1] http://forum.world.st/Create-JS-Object-in-Smalltalk-tt4769429.html
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Baffling Difference between Workspace and Inspector

Herby Vojčík


Sean P. DeNigris wrote:
> I'm assuming this problem is related to the one I described [1] last time I
> did a "serious" Amber project.
>
>      `(jQuery getJSON: './suppliers.json') responseJSON` ->  DNU
> but:
>      `(jQuery getJSON: './suppliers.json') inspect` and then `self
> responseJSON` from that inspector works!
>
> I still can't wrap my head around the difference :/

Asynchrony? ;-)

You're using jQuery API the wrong way, you should not treat it as synchronous, but fully embrace the async way.

(jQuery ajax: #{'dataType'->'json'. 'url'->'./suppliers.json'))
done: [ :jsonResponse | ... ];
fail: [ "error" ]

And last, but not least: don't use 'jQuery'. You get hurt when your code fails in production. From version 0.14.14, jQuery is not part of Amber, you should imports 'Wrappers-JQuery' and use 'JQuery current' (more in wiki migration guide).

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Baffling Difference between Workspace and Inspector

Sean P. DeNigris
Administrator
Herby Vojčík wrote
Asynchrony? ;-)
I was hoping you wouldn't say that ha ha!

What if you really do want to wait for the value? In this case, I am interfacing with code imported from Pharo (which I would like to remain compatible). It expects a value to be returned...
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Baffling Difference between Workspace and Inspector

Herby Vojčík


Sean P. DeNigris wrote:
> Herby Vojčík wrote
>> Asynchrony? ;-)
>
> I was hoping you wouldn't say that ha ha!
>
> What if you really do want to wait for the value? In this case, I am
> interfacing with code imported from Pharo (which I would like to remain
> compatible). It expects a value to be returned...

Never used that, everyone discourages it, but there _is_ an option to
make that call synchronous. Look in jQuery docs.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Baffling Difference between Workspace and Inspector

Herby Vojčík


Herby Vojčík wrote:

>
>
> Sean P. DeNigris wrote:
>> Herby Vojčík wrote
>>> Asynchrony? ;-)
>>
>> I was hoping you wouldn't say that ha ha!
>>
>> What if you really do want to wait for the value? In this case, I am
>> interfacing with code imported from Pharo (which I would like to remain
>> compatible). It expects a value to be returned...
>
> Never used that, everyone discourages it, but there _is_ an option to
> make that call synchronous. Look in jQuery docs.

But even if you escape this time, you cannot escape entirely, as Pharo
has green threads, but Amber doesn't, as JS doesn't and is built around
callbacks (or promises if you like that more).

Code that deliberately waits in one thread, letting others go on, simply
cannot be ported as-is and must be rewritten.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Baffling Difference between Workspace and Inspector

Sean P. DeNigris
Administrator
Herby Vojčík wrote
> Never used that, everyone discourages it, but there _is_ an option to
> make that call synchronous. Look in jQuery docs.
...

Code that deliberately waits in one thread, letting others go on, simply
cannot be ported as-is and must be rewritten.
Noted, but in this case, it feels like the right thing to do. I ended up with:
  response := JQuery current ajax: #{ #dataType -> 'json'. #url -> './egg_suppliers.json'. #async -> false }.
which I adapted from http://stackoverflow.com/questions/13009755/getjson-synchronous
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Baffling Difference between Workspace and Inspector

jtuchel
Sean,

I don't remember the details any more, but I spent quite some time trying to use async: false in $.ajax() in our Seaside app (which doesn't really matter) and decided to give up on it after wasting hours, maybe days hunting some problem. Shame on me, but I can't tell for sure any more what the problem was. Maybe it was IE or other shit of that kind.

So I advice you to take the strong discouragement about synchronous ajax seriously. It will pay back either way ;-)


Joachim

Am Montag, 15. Juni 2015 22:01:02 UTC+2 schrieb Sean DeNigris:
Herby Vojčík wrote
>> Never used that, everyone discourages it, but there _is_ an option to
>> make that call synchronous. Look in jQuery docs.
> ...
>
> Code that deliberately waits in one thread, letting others go on, simply
> cannot be ported as-is and must be rewritten.

Noted, but in this case, it feels like the right thing to do. I ended up
with:
  response := JQuery current ajax: #{ #dataType -> 'json'. #url ->
'./egg_suppliers.json'. #async -> false }.
which I adapted from
<a href="http://stackoverflow.com/questions/13009755/getjson-synchronous" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F13009755%2Fgetjson-synchronous\46sa\75D\46sntz\0751\46usg\75AFQjCNGvl41kEID1D1r9Md2Z682R9qXV8Q';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F13009755%2Fgetjson-synchronous\46sa\75D\46sntz\0751\46usg\75AFQjCNGvl41kEID1D1r9Md2Z682R9qXV8Q';return true;">http://stackoverflow.com/questions/13009755/getjson-synchronous



-----
Cheers,
Sean
--
View this message in context: <a href="http://forum.world.st/Baffling-Difference-between-Workspace-and-Inspector-tp4832487p4832524.html" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fforum.world.st%2FBaffling-Difference-between-Workspace-and-Inspector-tp4832487p4832524.html\46sa\75D\46sntz\0751\46usg\75AFQjCNHBEYL2QiQbj3AqCpZVjSkxohIPNw';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fforum.world.st%2FBaffling-Difference-between-Workspace-and-Inspector-tp4832487p4832524.html\46sa\75D\46sntz\0751\46usg\75AFQjCNHBEYL2QiQbj3AqCpZVjSkxohIPNw';return true;">http://forum.world.st/Baffling-Difference-between-Workspace-and-Inspector-tp4832487p4832524.html
Sent from the Amber Smalltalk mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.