Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feature) Implement oo.WorkerMixin. #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@

## Features (to be implemented)

What can should do:
- **Add new tasks to the worker.** Tasks contain a callback function and a metadata object. They are used for conditional templating.

- add new tasks to the worker (these tasks are used for conditional templating)
- sort the tasks and partition then into batches.
- define a trigger that starts processing the tasks
- hold a status, and a trigger that stops processing these tasks
- define a context where tasks or task batches are executed
- **Sort tasks by priority and partion them into batches.**

- **Allow to define triggers that start or stop processing of tasks.**

- **Provide the status of the process.**

- **Allow to provide an exection context where a task or a task batch is processed.**

## Usage

Expand All @@ -44,11 +46,11 @@ $ bower install --save oolymer/oo-worker
Develop.

~~~
$ npm install
$ bower install --force-latest
$ npm run build:node:watch
$ npm run test:node:watch
$ npm run browser
$ yarn install
$ yarn install:bower
$ yarn build
$ yarn test
$ yarn start
~~~

Semantic versions.
Expand Down
45 changes: 31 additions & 14 deletions demo/oo-worker.demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<link rel="import" href="../../paper-spinner/paper-spinner-lite.html">
<link rel="import" href="../../paper-styles/paper-styles.html">
<link rel="import" href="../../paper-styles/paper-styles-classes.html">
<link rel="import" href="../oo-worker.html">
<link rel="import" href="../oo-worker-mixin.html">

<body unresolved>
<custom-style>
Expand All @@ -43,10 +43,10 @@
</style>
</custom-style>

<demo-element></demo-element>
<demo-page></demo-page>
</body>

<dom-module id="demo-element">
<dom-module id="demo-page">
<template>
<style>
:host {
Expand Down Expand Up @@ -137,7 +137,7 @@
<div class="section-head paper-font-subhead">section 1</div>
<div class="section-body">
<div class="section-item">
<oo-worker>item 0</oo-worker>
<oo-section>item 0</oo-section>
</div>
<div class="section-item">item 1</div>
<div class="section-item">item 2</div>
Expand Down Expand Up @@ -174,9 +174,9 @@

<script>
window.addEventListener("WebComponentsReady", () => {
class DemoElement extends Polymer.Element {
class DemoPage extends oo.WorkerMixin(Polymer.Element) {
static get is() {
return "demo-element"
return "demo-page"
}

static get properties() {
Expand All @@ -199,21 +199,38 @@
this.loading = !this.loading
})

const worker = this.shadowRoot.querySelector("oo-worker")
console.log(worker)

this.items = []
for (const task of worker._worker._tasks.data) {
this.items.push(task.data)
}
const worker = this._workers.default
console.log(worker.numOfTasks, worker.numOfTasksWaiting, worker.numOfTasksRunning)
}

_timeout(delayMillis) {
return Polymer.Async.timeOut.after(delayMillis)
}
}

window.customElements.define(DemoElement.is, DemoElement)
window.customElements.define(DemoPage.is, DemoPage)
})
</script>
</dom-module>

<dom-module id="demo-section">
<template>
<style>
:host {
display: block;
}
</style>
</template>

<script>
window.addEventListener("WebComponentsReady", () => {
class DemoSection extends oo.WorkerMixin(Polymer.Element) {
static get is() {
return "demo-section"
}
}

window.customElements.define(DemoSection.is, DemoSection)
})
</script>
</dom-module>
35 changes: 35 additions & 0 deletions oo-worker-mixin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<link rel="import" href="../polymer/polymer-element.html">

<script src="oo-worker.min.js"></script>

<script>
// Use local function scope to avoid bleeding too many variables into global `window`.
(function () {
// Declare or reuse global namespace.
window.oo = window.oo || {}

oo.defaultWorker = new oo.Worker("default", {
concurrent: 10
})

/**
* A custom element class mixin that provides a collection of utility methods.
*
* @polymerMixin
* @memberof oo
*/
oo.WorkerMixin = Polymer.dedupingMixin(function (superClass) {

/**
* @polymerMixinClass
*/
return class WorkerMixin extends superClass {
ready() {
super.ready()
this._workers = { default: oo.defaultWorker }
}
}

})
}())
</script>
2 changes: 1 addition & 1 deletion oo-worker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.