Using JavaScript Promises with CLOG (advanced) #157
rabbibotton
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
So as most know using javascript with CLOG is fairly easy, you just use the functions js-execute or js-query when a result desired. However "modern" javascript frequently uses promises. So here is a tip on how to use them:
So lets say I setup a panel with two controls a file picker and a button
I set an event on the panel in code or in on-create
(set-on-event-with-data panel "result" (lambda (obj data) (print data)))
In the on-click or some place else, I request the contents of the file picker file which returns a promise of the text of the file. I use .then in JS with a call to trigger to then trigger the custom even "panel":
(js-execute target (format nil "~A[0].files[0].text().then(function(r){~A.trigger('result',r);})" (jquery (file-control panel)) (jquery (file-control panel))))
In general using custom events (set-on-event or set-on-event-with data) are the best way to work with JS's model of async programming.
Beta Was this translation helpful? Give feedback.
All reactions