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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Weacast ScalarField | Issue #8 with 1.3.3</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> | |
<link rel="stylesheet" href="//unpkg.com/[email protected]/dist/leaflet.css" /> | |
<link href="https://fonts.googleapis.com/css?family=Roboto:100,400" rel="stylesheet"> | |
<style> |
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
function activateHooks (service, serviceHooks) { | |
// Iterate over hook types (before, after) | |
_.forOwn(serviceHooks, (hooksDefinition, stage) => { | |
// Iterate over hooks to create the hook pipeline | |
let pipeline = [] | |
_.forOwn(hooksDefinition, (hookOptions, hookName) => { | |
// Jump from name/options to the real hook function | |
pipeline.push(hooks[hookName](hookOptions)) | |
}) | |
// Replace hooks in place so that we can use it directly with Feathers after |
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
import _ from 'lodash' | |
class Service { | |
constructor (generators = {}) { | |
this.generators = {} | |
_.forOwn(generators, (value, key) => { | |
this.registerGenerator(key, value) | |
}) | |
} |
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
class StoresService extends Service { | |
... | |
async create (data, params = {}) { | |
let { type, options } = data | |
return this.generate(type, options)) | |
} | |
... | |
} |
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
let job = { | |
// Options for job executor | |
options: { | |
workersLimit: 4 | |
}, | |
// Store to be used | |
store: { | |
id: 'job-store', | |
type: 'fs', | |
options: { path: './data' } |
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
class JobsService extends Service { | |
setup (app, path) { | |
this.tasksService = app.service('tasks') | |
} | |
async create (data, params = {}) { | |
let { type, options, store, tasks } = data | |
return this.generate(type, options, store, tasks) | |
} |
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
class TasksService extends Service { | |
create (data, params) { | |
let { id, type, options } = data | |
let { store } = params | |
return new Promise((resolve, reject) => { | |
let taskStream = this.generate(type, options) | |
taskStream | |
.on('error', reject) | |
.pipe(store.createWriteStream({ |
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
const delay = (duration) => | |
new Promise(resolve => setTimeout(resolve, duration)) | |
async function asyncWithAwait(prefix) { | |
console.log(prefix + ' before await') | |
await delay(1000) | |
console.log(prefix + ' after await') | |
} | |
function asyncWithPromise(prefix) { |
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
async function run() { | |
let prefix = '(1)' | |
console.log(prefix + ' with await') | |
asyncWithAwait(prefix) | |
console.log(prefix + ' with promise') | |
asyncWithPromise(prefix) | |
console.log(prefix + ' after all') | |
} | |
run() |
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
async function run() { | |
let prefix = '(2)' | |
console.log(prefix + ' with await') | |
await asyncWithAwait(prefix) | |
console.log(prefix + ' with promise') | |
asyncWithPromise(prefix).then(_ => console.log(prefix + ' after all')) | |
} | |
run() |