@pelagiccreatures/sargasso
Advanced tools
Comparing version 0.5.14 to 0.5.15
@@ -29,9 +29,14 @@ class myClass extends sargasso.Sargasso { | ||
// stringify it | ||
const txtFunction = 'onmessage = ' + mySlowFunction.toString() | ||
// create the worker. managed by sargasso | ||
const worker = this.startWorker('myworkId', txtFunction) | ||
this.workerStart('myworkId', '/example/test-worker.js') | ||
// listen to the worker | ||
worker.onmessage = (e) => { | ||
// make the worker do work | ||
this.workerPost('myworkId', 12) | ||
} | ||
workerOnMessage (id, e) { | ||
if (id === 'myworkId') { | ||
const frame = () => { | ||
@@ -42,5 +47,3 @@ this.element.innerHTML = e.data | ||
} | ||
// make the worker work | ||
worker.postMessage(12) | ||
super.workerOnMessage(id, e) | ||
} | ||
@@ -47,0 +50,0 @@ } |
@@ -352,12 +352,8 @@ /** | ||
let worker = this.startWorker('thing',mycode) | ||
this.workerStart('pointless-math', mycode) | ||
worker.onmessage = (e) => { | ||
console.log(e.data) // we got the result | ||
} | ||
worker.postMessage(12) // start computing | ||
this.workerPost('pointless-math', 16) | ||
*/ | ||
startWorker (id, codeOrURL) { | ||
workerStart (id, codeOrURL) { | ||
let blobURL = codeOrURL | ||
@@ -380,5 +376,18 @@ | ||
this.workers[id].onmessage = (e) => { | ||
this.workerOnMessage(id, e) | ||
} | ||
return this.workers[id] | ||
} | ||
workerPost (id, message) { | ||
if (this.workers[id]) { | ||
this.workers[id].postMessage(message) | ||
} | ||
} | ||
// subclass can overide this to listen to workers | ||
workerOnMessage (id, e) {} | ||
// stop a worker | ||
@@ -385,0 +394,0 @@ stopWorker (id) { |
{ | ||
"name": "@pelagiccreatures/sargasso", | ||
"version": "0.5.14", | ||
"version": "0.5.15", | ||
"description": "Simple, Fast, Reactive, supervised Javascript controllers for html elements.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -7,3 +7,3 @@ # @PelagicCreatures/Sargasso | ||
This is a very lightweight, pure ES6 (with only few dependencies) framework which aims to use the most advanced stable features of modern browsers to maximum effect leaving as much historical cruft in the past as possible. The result is lean, highly performant and clean code that simplifies the complex requirements of modern progressive web apps and web sites. | ||
This is a very lightweight, pure ES6 framework (with only few dependencies) which aims to use the most advanced stable features of modern browsers to maximum effect leaving the historical cruft, kludges and code barnacles infesting older web frameworks behind. The result is lean, highly performant and clean code that simplifies the complex requirements of modern progressive web apps and web sites. | ||
@@ -16,5 +16,5 @@ ``` | ||
HTML elements sometimes need a nervous system to see and respond to what's going on around them - Sargasso element controllers are fully aware of their environment making many things are possible – lazy loading, screen size appropriate images and content, parallax scrolling effects, form validators, API endpoint controllers to name a few. | ||
HTML elements sometimes need a nervous system to see and respond to what's going on around them - Sargasso element controllers are fully aware of their environment making many things possible – HIJAX, lazy loading, screen size appropriate images and content, parallax scrolling effects, form validators, API endpoint controllers to name a few. | ||
HIJAX made easy - this framework implements an asynchronous page loading scheme which supports deep linking and lightning fast page loads where only dynamic content areas are merged between pages leaving css, js, web workers and wrapper elements intact. Sargasso controller instances are created as needed when their element appears in the DOM and destroyed when their element is removed. | ||
HIJAX made easy - this framework implements an asynchronous page loading scheme which supports deep linking and lightning fast page loads where only dynamic content areas are merged between pages leaving css, js, web workers and wrapper elements intact. Sargasso controller instances are managed as needed when their element appears in the DOM and destroyed when their element is removed. | ||
@@ -224,5 +224,7 @@ Performance is optimized with shared event listeners which are fully debounced during large updates. Services are provided to schedule content changes using the browser's animation frame event loop and computation heavy tasks can be easily offloaded to managed web workers resulting in highly performant pages. | ||
class MySubClass extends Sargasso { | ||
... | ||
someMethod() { | ||
// define some code to run in the worker | ||
@@ -239,12 +241,18 @@ | ||
// create worker | ||
let worker = this.startWorker('workerbee', mycode) | ||
// create the worker to be managed by sargasso and give it an id | ||
this.workerStart('myworkId', mycode) | ||
// listen for result | ||
worker.onmessage = (e) => { | ||
console.log(e.data) // "Done doing pointless math: 50934038.24768489" | ||
// make the worker do work | ||
this.workerPost('myworkId', 12) | ||
} | ||
// listen for worker events | ||
workerOnMessage (id, e) { | ||
if (id === 'myworkId') { | ||
const frame = () => { | ||
this.element.innerHTML = e.data | ||
} | ||
this.queueFrame(frame) | ||
} | ||
// start computing | ||
worker.postMessage(12) | ||
super.workerOnMessage(id, e) | ||
} | ||
@@ -256,3 +264,3 @@ } | ||
### Viewing the Test Page in the example directory | ||
To use Hijax you have to serve the files (window.popstate can't deal with file://) so run this in the project directory | ||
To use Hijax you have to serve the files (window.popstate can't deal with file://) so run SimpleHTTPServer in the project directory to see demo page | ||
``` | ||
@@ -259,0 +267,0 @@ python -m SimpleHTTPServer 8000 |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
187534
21
2143
266