### 4Dv14 + \$4d object in Web Area

Phillip Hall (4/17/14 11:40AM)
Lee Hinde (4/18/14 2:53PM)
Joshua Fletcher (4/18/14 7:46PM)

Phillip Hall (4/17/14 11:40 AM)

<55F2F9830C7D614E96168F040BA62F9915463B749F@...

Hi,

I am working on a project where we would like to use the Web Area to
evaluate some arbitrary Javascript and return a result to 4D.

One requirement is that the Javascript must be able to call back to 4D
to retrieve data, do its calculations and then return the result.

We would like to be able to evaluate something like the following
Javascript method.

function calculateSomeValue () {
¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬
?=C2?=C2?var dataFrom4D = \$4d.FourDMethod();
¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬
?=C2?=C2?var moreDataFrom4D = \$4d.Another4DMethod(datafrom4D);

¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬=A0¬
?=C2?=C2?return dataFrom4D + moreDataFrom4D;
}

The problem is that the call to \$4d.method is asynchronous and the
result is return in a call back method. ¬=A0This causes the
synchronous
execution chain to break.

Does anyone know of a way to use a \$4d.method call synchronously?

Thanks
Phillip

Phillip Hall

4D Developer

P: +61 2 8273 7500 | F: +61 2 9247 7544
W: www.leap.com.au E:
phillip.hall@leap.com.au<mailto:phillip.hall@leap.com.au>
A: Level 8, 207 Kent Street, Sydney NSW 2000
National Sales: 1300 607 625 | National HelpDesk: 1800 007 709

[http://www.leap.com.au/graphics/email_footers/LEAP-ex.jpg]

________________________________
This message contains confidential information and is intended only
for 4d_tech@... If you are not 4d_tech@... you
should not disseminate, distribute or copy this e-mail. Please notify
phillip.hall@... immediately by e-mail if you have received
this e-mail by mistake and delete this e-mail from your system.
phillip.hall@... AND LEAP LEGAL SOFTWARE do not accept
liability for any errors or omissions in the contents of this message,
which arise as a result of e-mail transmission as information could be
intercepted, corrupted, lost, destroyed, arrive late or incomplete, or
contain viruses.

Lee Hinde (4/18/14 2:53 PM)

<CA+ePoMzp8f7zLD5VCHCM7tJZdc_OEc9y_HbYqVKLu5N177YgcA@...

What he said. This is a nice article about promises with jQuery that
came
through the feed today:

http://davidwalsh.name/write-javascript-promises

On Fri, Apr 18, 2014 at 10:46 AM, Joshua Fletcher <JFletcher@...
wrote:

color><param>00000,0000,DDEE/param>BBut this is NOT the recommended
solution! Based on some limited research,
"promises" are the way to do what you want. ?Support for promises
varies,
there are several JS modules that abstract it to make it easier to use
and
it's supposed to be part of the next version of JS:

http://www.html5rocks.com/en/tutorials/es6/promises

This is a popular promise module called "Q":

https://github.com/kriskowal/q

Or, if possible you can cheat, don't call Another4DMethod from JS.
?Call
Another4DMethod from FourDMethod.

/color>

Joshua Fletcher (4/18/14 7:46 PM)

Maybe it's worth pointing this out (maybe not?): this isn't a 4D
question, it's a Javascript question. There's a wealth of information
sequential execution in JavaScript?" There are entire JS design
patterns devoted to solving this problem. ?I'm not a JS expert, so I
don't really want to tell you what to do but here's some information
that might get you pointed in the right direction:

What you're intuitively trying to do is called Continuation-passing
style (CPS):

http://en.wikipedia.org/wiki/Continuation-passing_style

Here's an article about it with some basic examples in JS:

http://www.2ality.com/2012/06/continuation-passing-style.html

But this is NOT the recommended solution! Based on some limited
research, "promises" are the way to do what you want. ?Support for
promises varies, there are several JS modules that abstract it to make
it easier to use and it's supposed to be part of the next version of
JS:

http://www.html5rocks.com/en/tutorials/es6/promises

This is a popular promise module called "Q":

https://github.com/kriskowal/q

Or, if possible you can cheat, don't call Another4DMethod from JS.
?Call Another4DMethod from FourDMethod.

Kind regards,

Josh

--
Josh Fletcher
Technical Account Manager
4D, Inc

color><param>00000,0000,DDEE/param>
/color>

-----Original Message-----
color><param>00000,0000,DDEE/param>DDoes anyone know of a way to use a
\$4d.method call synchronously?
/color>

Summary created 4/18/14 at 6:15PM by Intellex Corporation