Fix lint errors

This commit is contained in:
Brandon Keepers
2016-11-22 21:34:47 -06:00
parent d986a18c56
commit 8dd579c7f4

View File

@@ -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'});