From a8f7be32c603f57effcf3f11c39ddbe8447344ae Mon Sep 17 00:00:00 2001 From: atomiks Date: Thu, 4 Jan 2018 04:07:32 +1100 Subject: [PATCH 1/4] Update runAsync.md --- snippets/runAsync.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/snippets/runAsync.md b/snippets/runAsync.md index 8ab34943e..e2573a061 100644 --- a/snippets/runAsync.md +++ b/snippets/runAsync.md @@ -8,10 +8,7 @@ Return a promise, listening for `onmessage` and `onerror` events and resolving t ```js const runAsync = fn => { - const blob = ` - var fn = ${fn.toString()}; - this.postMessage(fn()); - `; + const blob = `var fn = ${fn.toString()}; postMessage(fn());`; const worker = new Worker( URL.createObjectURL(new Blob([blob]), { type: 'application/javascript; charset=utf-8' @@ -31,9 +28,9 @@ const runAsync = fn => { ```js const longRunningFunction = () => { let result = 0; - for (var i = 0; i < 1000; i++) { - for (var j = 0; j < 700; j++) { - for (var k = 0; k < 300; k++) { + for (let i = 0; i < 1000; i++) { + for (let j = 0; j < 700; j++) { + for (let k = 0; k < 300; k++) { result = result + i + j + k; } } From fa1ca0a7676e62dafacf7fe9e1ba7db027c77cb0 Mon Sep 17 00:00:00 2001 From: Pl4gue Date: Wed, 3 Jan 2018 18:58:01 +0100 Subject: [PATCH 2/4] responsive github ribbon --- docs/index.html | 2 +- static-parts/index-start.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.html b/docs/index.html index 645a1252f..569abb241 100644 --- a/docs/index.html +++ b/docs/index.html @@ -53,7 +53,7 @@ document.body.removeChild(textArea); } }, false); - }

 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
+      }

 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
 
Promise.resolve([1, 2, 3])
   .then(call('map', x => 2 * x))
   .then(console.log); //[ 2, 4, 6 ]
diff --git a/static-parts/index-start.html b/static-parts/index-start.html
index fd7122025..b46cd2dee 100644
--- a/static-parts/index-start.html
+++ b/static-parts/index-start.html
@@ -81,7 +81,7 @@
         }
       });
     
-    
+    
     

 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less. From 46e6183312e676e6be6f376db9bf008a8edc7c4a Mon Sep 17 00:00:00 2001 From: Pl4gue Date: Wed, 3 Jan 2018 19:02:27 +0100 Subject: [PATCH 3/4] build --- docs/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.html b/docs/index.html index 569abb241..c5e88732f 100644 --- a/docs/index.html +++ b/docs/index.html @@ -53,7 +53,7 @@ document.body.removeChild(textArea); } }, false); - }

 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
+      }

 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
 
Promise.resolve([1, 2, 3])
   .then(call('map', x => 2 * x))
   .then(console.log); //[ 2, 4, 6 ]

From 612db1c4bf5b43134340543a3793b4087264e634 Mon Sep 17 00:00:00 2001
From: 30secondsofcode <30secondsofcode@gmail.com>
Date: Wed, 3 Jan 2018 18:17:12 +0000
Subject: [PATCH 4/4] Travis build: 980

---
 README.md       | 11 ++++-------
 docs/index.html | 11 ++++-------
 2 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/README.md b/README.md
index 1d4cfc28b..c8c3c420d 100644
--- a/README.md
+++ b/README.md
@@ -2097,10 +2097,7 @@ Return a promise, listening for `onmessage` and `onerror` events and resolving t
 
 ```js
 const runAsync = fn => {
-  const blob = `
-    var fn = ${fn.toString()};
-    this.postMessage(fn());
-  `;
+  const blob = `var fn = ${fn.toString()}; postMessage(fn());`;
   const worker = new Worker(
     URL.createObjectURL(new Blob([blob]), {
       type: 'application/javascript; charset=utf-8'
@@ -2123,9 +2120,9 @@ const runAsync = fn => {
 ```js
 const longRunningFunction = () => {
   let result = 0;
-  for (var i = 0; i < 1000; i++) {
-    for (var j = 0; j < 700; j++) {
-      for (var k = 0; k < 300; k++) {
+  for (let i = 0; i < 1000; i++) {
+    for (let j = 0; j < 700; j++) {
+      for (let k = 0; k < 300; k++) {
         result = result + i + j + k;
       }
     }
diff --git a/docs/index.html b/docs/index.html
index 645a1252f..b75d36899 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -422,10 +422,7 @@ elementIsVisibleInViewport(el, true); // true // (partially visible)
   asLink ? (window.location.href = url) : window.location.replace(url);
 
redirect('https://google.com');
 

runAsync

Runs a function in a separate thread by using a Web Worker, allowing long running functions to not block the UI.

Create a new Worker using a Blob object URL, the contents of which should be the stringified version of the supplied function. Immediately post the return value of calling the function back. Return a promise, listening for onmessage and onerror events and resolving the data posted back from the worker, or throwing an error.

const runAsync = fn => {
-  const blob = `
-    var fn = ${fn.toString()};
-    this.postMessage(fn());
-  `;
+  const blob = `var fn = ${fn.toString()}; postMessage(fn());`;
   const worker = new Worker(
     URL.createObjectURL(new Blob([blob]), {
       type: 'application/javascript; charset=utf-8'
@@ -442,9 +439,9 @@ elementIsVisibleInViewport(el, true); // true // (partially visible)
 };
 
const longRunningFunction = () => {
   let result = 0;
-  for (var i = 0; i < 1000; i++) {
-    for (var j = 0; j < 700; j++) {
-      for (var k = 0; k < 300; k++) {
+  for (let i = 0; i < 1000; i++) {
+    for (let j = 0; j < 700; j++) {
+      for (let k = 0; k < 300; k++) {
         result = result + i + j + k;
       }
     }