Guest User

Untitled

a guest
Feb 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. ///// code.gs: the server side /////
  2.  
  3. var serverService = (function() {
  4. // create and initialise the service
  5. var service = new ServerClass(42); // new instance of something
  6. service.name = 'foo';
  7. // return the service
  8. return function() {
  9. var args = Array.prototype.slice.call(arguments); // because the server doesn't support the spread operator
  10. return service[args.shift()].apply(service, args);
  11. };
  12. })();
  13.  
  14.  
  15. ///// bundle.js: the client side /////
  16.  
  17. var clientService = (function() {
  18. return function(...args) {
  19. return new Promise(function (resolve, reject) {
  20. google.script.run
  21. .withSuccessHandler(resolve)
  22. .withFailureHandler(reject)
  23. serverService(...args);
  24. });
  25. }; // async services promise wrapper
  26. })();
  27.  
  28. clientService('set', 777)
  29. .then(console.log)
  30. .catch(console.warn);
  31.  
  32. var serverService = (function serverService() {...})();
Add Comment
Please, Sign In to add comment