Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///// code.gs: the server side /////
- var serverService = (function() {
- // create and initialise the service
- var service = new ServerClass(42); // new instance of something
- service.name = 'foo';
- // return the service
- return function() {
- var args = Array.prototype.slice.call(arguments); // because the server doesn't support the spread operator
- return service[args.shift()].apply(service, args);
- };
- })();
- ///// bundle.js: the client side /////
- var clientService = (function() {
- return function(...args) {
- return new Promise(function (resolve, reject) {
- google.script.run
- .withSuccessHandler(resolve)
- .withFailureHandler(reject)
- serverService(...args);
- });
- }; // async services promise wrapper
- })();
- clientService('set', 777)
- .then(console.log)
- .catch(console.warn);
- var serverService = (function serverService() {...})();
Add Comment
Please, Sign In to add comment