From 8dd579c7f4aaaf74f6aeebb563aaf35aa3bf549d Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Tue, 22 Nov 2016 21:34:47 -0600 Subject: [PATCH] Fix lint errors --- scratchpad.js | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/scratchpad.js b/scratchpad.js index 02fe71d..18c6a63 100644 --- a/scratchpad.js +++ b/scratchpad.js @@ -9,30 +9,30 @@ class IssuesPlugin { // each method takes a `context` argument that has access to the context it was called in. comment(context, message) { // Methods that make network calls should return a promise - return new Promise((resolve, reject) => { + return new Promise(resolve => { setTimeout(() => { - console.log("comment:", message, {state: this.state, context}); + console.log('comment:', message, {state: this.state, context}); resolve(); }, 1000); }); } close(context) { - return new Promise((resolve, reject) => { + return new Promise(resolve => { setTimeout(() => { - console.log("close", {context}); + console.log('close', {context}); resolve(); }, 1000); }); } - fail(context) { - return Promise.reject("Rejecting a promise stops the chain"); + fail() { + return Promise.reject('Rejecting a promise stops the chain'); } } -PLUGINS = [ - new IssuesPlugin("state") +const PLUGINS = [ + new IssuesPlugin('state') ]; class Workflow { @@ -40,29 +40,27 @@ class Workflow { this.stack = []; this.api = {}; - PLUGINS.forEach(plugin => { + for(const plugin of PLUGINS) { // Get all the property names of the plugin - for(let method of Object.getOwnPropertyNames(plugin.constructor.prototype)) { - if(method !== 'constructor') { + for (const method of Object.getOwnPropertyNames(plugin.constructor.prototype)) { + if (method !== 'constructor') { // Define a new function in the API for this plugin method, forcing // the binding to this to prevent any tampering. this.api[method] = this.proxy(plugin, method).bind(this); } } - }); + } } proxy(plugin, method) { // This function is what gets exposed to the sandbox return (...args) => { // Push new function on the stack that calls the plugin method with a context. - this.stack.push((context) => { - return plugin[method].call(plugin, context, ...args); - }); + this.stack.push(context => plugin[method](context, ...args)); // Return the API to allow methods to be chained. return this.api; - } + }; } execute(context) { @@ -73,10 +71,10 @@ class Workflow { } } -workflow = new Workflow(); +const workflow = new Workflow(); // workflow.api would be passed into a sandbox -workflow.api.comment("Hello").close().fail().comment("this won't get called"); +workflow.api.comment('Hello').close().fail().comment('this will not get called'); // Execute the workflow with the given context workflow.execute({name: 'Brandon'});