@pelagiccreatures/sargasso
Advanced tools
Comparing version 0.5.11 to 0.5.12
@@ -13,5 +13,22 @@ class myClass extends sargasso.Sargasso { | ||
this.addClass('tada') | ||
this.offLoadTask() | ||
} | ||
this.queueFrame(frame) | ||
} | ||
offLoadTask () { | ||
const code = `onmessage = function(e) { | ||
console.log('starting web worker work') | ||
for(let i = 0; i < e.data; i++){ | ||
// do something 100k times | ||
} | ||
postMessage({status:'ok'}) | ||
}` | ||
const worker = this.startWorker('myworkId', code) | ||
worker.onmessage = function (e) { | ||
this.element.innerHTML = 'done counting to 100k' | ||
this.stopWorker('myworkId') | ||
} | ||
worker.postMessage(1000000) | ||
} | ||
} | ||
@@ -18,0 +35,0 @@ |
@@ -60,2 +60,3 @@ /** | ||
this.isInViewport = false | ||
this.workers = {} | ||
@@ -179,2 +180,4 @@ if (!this.element.registeredResponsiveControllers) { | ||
this.stopAllWorkers() | ||
if (this.element.registeredResponsiveControllers) { | ||
@@ -304,2 +307,25 @@ if (this.element.registeredResponsiveControllers.indexOf(this) !== -1) { | ||
startWorker (id, code) { | ||
const blob = new Blob(code, { | ||
type: 'text/javascript' | ||
}) | ||
const blobURL = URL.createObjectURL(blob) | ||
this.workers[id] = new Worker(blobURL) | ||
URL.revokeObjectURL(blobURL) | ||
return this.workers[id] | ||
} | ||
stopWorker (id) { | ||
if (this.workers[id]) { | ||
this.workers[id].terminate() | ||
delete this.workers[id] | ||
} | ||
} | ||
stopAllWorkers () { | ||
for (const worker in this.workers) { | ||
this.stopWorker(worker) | ||
} | ||
} | ||
// experimental | ||
@@ -306,0 +332,0 @@ |
{ | ||
"name": "@pelagiccreatures/sargasso", | ||
"version": "0.5.11", | ||
"version": "0.5.12", | ||
"description": "Simple, Fast, Reactive, supervised Javascript controllers for html elements.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -77,3 +77,3 @@ # @PelagicCreatures/Sargasso | ||
``` | ||
<script src="https://cdn.jsdelivr.net/npm/@pelagiccreatures/sargasso@0.5.10/dist/sargasso.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@pelagiccreatures/sargasso/dist/sargasso.js"></script> | ||
``` | ||
@@ -95,3 +95,3 @@ | ||
### HIJAX | ||
Is the function you should call to load a new page. Once loaded, new pages are merged with the current page only replacing elements marked with 'data-hijax="true"'. Sargasso automatically captures `<a href="..">` tags and calls the LoadPageHandler instead of letting the browser load pages. `LoadPageHandler(href)` | ||
Is the function you should call to load a new page. Once loaded, new pages are merged with the current page only replacing elements marked with `data-hijax="true"`. Sargasso automatically captures `<a href="..">` tags and calls the LoadPageHandler instead of letting the browser load pages. `LoadPageHandler(href)` | ||
@@ -153,28 +153,28 @@ EG. instead of `location.href= '/home'`, use `LoadPageHandler('/home')` | ||
``` | ||
class MyButtonClass extends Sargasso { | ||
class MyButtonClass extends Sargasso { | ||
// listen for click | ||
start() { | ||
super.start() | ||
// listen for click | ||
start() { | ||
super.start() | ||
this.clicker = (e) => { | ||
this.clicked() | ||
} | ||
this.element.addEventListener('click', this.clicker, false) | ||
this.clicker = (e) => { | ||
this.clicked() | ||
} | ||
this.element.addEventListener('click', this.clicker, false) | ||
} | ||
// cleanup listener | ||
sleep() { | ||
this.element.removeEventListener('click', this.clicker) | ||
super.sleep() | ||
} | ||
// cleanup listener | ||
sleep() { | ||
this.element.removeEventListener('click', this.clicker) | ||
super.sleep() | ||
} | ||
// use an animation frame to mutate the DOM | ||
clicked() { | ||
let frame = () { | ||
this.addClass('clicked') | ||
} | ||
this.queueFrame(frame) | ||
// use an animation frame to mutate the DOM | ||
clicked() { | ||
let frame = () { | ||
this.addClass('clicked') | ||
} | ||
this.queueFrame(frame) | ||
} | ||
} | ||
@@ -181,0 +181,0 @@ Then in HTML: |
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
181693
2060