Last active
January 25, 2019 03:39
-
-
Save Woody88/814f94d9a64f3f8612f4cf7d5659fdd2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| exports._callApex = function (fullyQualifiedApexMethodName){ | |
| return function(apexMethodParameters){ | |
| return function(apexCallConfiguration){ | |
| return function(error){ | |
| return function(success){ | |
| return function (onError, onSuccess) { // and callbacks | |
| console.log('hello world2'); | |
| var responseHandler = function(result, event){ | |
| console.log(event); | |
| if (event.status){ | |
| onSuccess(success(result)); | |
| } | |
| else | |
| onSuccess(error(event.message)); | |
| } | |
| if (typeof Visualforce !== "undefined" && | |
| typeof Visualforce.remoting !== "undefined" && | |
| typeof Visualforce.remoting.Manager !== "undefined") { | |
| var req = Visualforce.remoting.Manager.invokeAction(fullyQualifiedApexMethodName, | |
| apexMethodParameters, | |
| responseHandler, | |
| apexCallConfiguration); | |
| } | |
| else { | |
| onSuccess(error("Could not find Visualforce Remote Object", "")); | |
| } | |
| // Return a canceler, which is just another Aff effect. | |
| return function (cancelError, cancelerError, cancelerSuccess) { | |
| console.log('hello world3'); | |
| req.cancel(); // cancel the request | |
| cancelerSuccess(); // invoke the success callback for the canceler | |
| }; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Apex.Internal where | |
| import Prelude | |
| import Data.Either (Either(..)) | |
| import Data.Function.Uncurried (Fn5, Fn6, runFn5, runFn6) | |
| import Data.Maybe (Maybe) | |
| import Effect.Aff (Aff) | |
| import Effect.Aff.Compat (EffectFnAff(..), fromEffectFnAff) | |
| import Foreign (Foreign) | |
| type ErrorMsg = String | |
| type ErrorTrace = String | |
| data ApexError = ApexError ErrorMsg | |
| instance showApexError :: Show ApexError where | |
| show (ApexError m) = m | |
| callApex :: forall c. String -> Foreign -> { |c} -> Aff (Either ApexError Foreign) | |
| callApex s args c = fromEffectFnAff $ runFn5 _callApex s args c (Left <<< ApexError) Right | |
| foreign import _callApex | |
| :: forall conf b. Fn5 String Foreign conf (String -> b) (Foreign -> b) (EffectFnAff b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment