From ba00a9645f1f93db06ea7d90f229ca0add336c0e Mon Sep 17 00:00:00 2001 From: atomiks Date: Sun, 25 Feb 2018 14:26:15 +1100 Subject: [PATCH 1/7] Create recordFrames.md --- snippets/recordFrames.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 snippets/recordFrames.md diff --git a/snippets/recordFrames.md b/snippets/recordFrames.md new file mode 100644 index 000000000..17a71300c --- /dev/null +++ b/snippets/recordFrames.md @@ -0,0 +1,37 @@ +### recordFrames + +Invokes the provided callback on each animation frame. + +Use recursion. Provided that `running` is `true`, continue invoking `window.requestAnimationFrame`. Return an object +with two methods `start` and `stop` to allow manual control of the recording. Omit the second argument, `autoStart`, +to implicitly call start when the function is invoked. + +```js +const recordFrames = (callback, autoStart = true) => { + let running = true, raf + const stop = () => { + running = false + cancelAnimationFrame(raf) + } + const start = () => { + running = true + run() + } + const run = () => { + raf = requestAnimationFrame(() => { + callback() + if (running) run() + }) + } + if (autoStart) start() + return { start, stop } +} +``` + +```js +const cb = () => console.log('Animation frame fired') +const recorder = recordFrames(cb) // logs 'Animation frame fired' on each animation frame +recorder.stop() // stops logging +recorder.start() // starts again +const recorder2 = recordFrames(cb, false) // `start` needs to be explicitly called to begin recording frames +``` From 206fd7f111f006292e148ebf55c524cf93d7493f Mon Sep 17 00:00:00 2001 From: atomiks Date: Sun, 25 Feb 2018 14:27:59 +1100 Subject: [PATCH 2/7] Update tag_database --- tag_database | 1 + 1 file changed, 1 insertion(+) diff --git a/tag_database b/tag_database index 54db11193..5eeee0a58 100644 --- a/tag_database +++ b/tag_database @@ -204,6 +204,7 @@ randomIntegerInRange:math,utility,random randomNumberInRange:math,utility,random readFileLines:node,array,string rearg:adapter,function +recordFrames:utility redirect:browser,url reducedFilter:array reduceSuccessive:array,function From b1a76d02b85781f799c4b96ac8c6fd7af3cc3902 Mon Sep 17 00:00:00 2001 From: atomiks Date: Sun, 25 Feb 2018 14:32:23 +1100 Subject: [PATCH 3/7] Update recordFrames.md --- snippets/recordFrames.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/snippets/recordFrames.md b/snippets/recordFrames.md index 17a71300c..938058ae9 100644 --- a/snippets/recordFrames.md +++ b/snippets/recordFrames.md @@ -2,9 +2,8 @@ Invokes the provided callback on each animation frame. -Use recursion. Provided that `running` is `true`, continue invoking `window.requestAnimationFrame`. Return an object -with two methods `start` and `stop` to allow manual control of the recording. Omit the second argument, `autoStart`, -to implicitly call start when the function is invoked. +Use recursion. Provided that `running` is `true`, continue invoking `window.requestAnimationFrame()` and invoking the +provided callback. Return an object with two methods `start` and `stop` to allow manual control of the recording. Omit the second argument, `autoStart`, to implicitly call `start` when the function is invoked. ```js const recordFrames = (callback, autoStart = true) => { From 05d2c0e55b870a2155c26e7049815891090421de Mon Sep 17 00:00:00 2001 From: atomiks Date: Sun, 25 Feb 2018 14:32:45 +1100 Subject: [PATCH 4/7] Update recordFrames.md --- snippets/recordFrames.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/recordFrames.md b/snippets/recordFrames.md index 938058ae9..cc158c7b2 100644 --- a/snippets/recordFrames.md +++ b/snippets/recordFrames.md @@ -2,7 +2,7 @@ Invokes the provided callback on each animation frame. -Use recursion. Provided that `running` is `true`, continue invoking `window.requestAnimationFrame()` and invoking the +Use recursion. Provided that `running` is `true`, continue invoking `window.requestAnimationFrame()` which invokes the provided callback. Return an object with two methods `start` and `stop` to allow manual control of the recording. Omit the second argument, `autoStart`, to implicitly call `start` when the function is invoked. ```js From c110cbff98c948086dd493f1f22d961176187455 Mon Sep 17 00:00:00 2001 From: atomiks Date: Wed, 28 Feb 2018 16:19:07 +1000 Subject: [PATCH 5/7] Update and rename recordFrames.md to recordAnimationFrames.md --- snippets/{recordFrames.md => recordAnimationFrames.md} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename snippets/{recordFrames.md => recordAnimationFrames.md} (73%) diff --git a/snippets/recordFrames.md b/snippets/recordAnimationFrames.md similarity index 73% rename from snippets/recordFrames.md rename to snippets/recordAnimationFrames.md index cc158c7b2..227eb23f5 100644 --- a/snippets/recordFrames.md +++ b/snippets/recordAnimationFrames.md @@ -1,4 +1,4 @@ -### recordFrames +### recordAnimationFrames Invokes the provided callback on each animation frame. @@ -6,7 +6,7 @@ Use recursion. Provided that `running` is `true`, continue invoking `window.requ provided callback. Return an object with two methods `start` and `stop` to allow manual control of the recording. Omit the second argument, `autoStart`, to implicitly call `start` when the function is invoked. ```js -const recordFrames = (callback, autoStart = true) => { +const recordAnimationFrames = (callback, autoStart = true) => { let running = true, raf const stop = () => { running = false @@ -29,8 +29,8 @@ const recordFrames = (callback, autoStart = true) => { ```js const cb = () => console.log('Animation frame fired') -const recorder = recordFrames(cb) // logs 'Animation frame fired' on each animation frame +const recorder = recordAnimationFrames(cb) // logs 'Animation frame fired' on each animation frame recorder.stop() // stops logging recorder.start() // starts again -const recorder2 = recordFrames(cb, false) // `start` needs to be explicitly called to begin recording frames +const recorder2 = recordAnimationFrames(cb, false) // `start` needs to be explicitly called to begin recording frames ``` From fd05ed7fa643770f37d0597d371145edc36c2066 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 6 Mar 2018 09:09:20 +0200 Subject: [PATCH 6/7] Update tag_database --- tag_database | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tag_database b/tag_database index 5eeee0a58..937c27eae 100644 --- a/tag_database +++ b/tag_database @@ -204,7 +204,7 @@ randomIntegerInRange:math,utility,random randomNumberInRange:math,utility,random readFileLines:node,array,string rearg:adapter,function -recordFrames:utility +recordAnimationFrames:browser,utility redirect:browser,url reducedFilter:array reduceSuccessive:array,function From 98dd21a59ef5be2eda010c5aeea85269dc09362e Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 6 Mar 2018 09:10:09 +0200 Subject: [PATCH 7/7] Update recordAnimationFrames.md --- snippets/recordAnimationFrames.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/snippets/recordAnimationFrames.md b/snippets/recordAnimationFrames.md index 227eb23f5..100504eb9 100644 --- a/snippets/recordAnimationFrames.md +++ b/snippets/recordAnimationFrames.md @@ -2,8 +2,10 @@ Invokes the provided callback on each animation frame. -Use recursion. Provided that `running` is `true`, continue invoking `window.requestAnimationFrame()` which invokes the -provided callback. Return an object with two methods `start` and `stop` to allow manual control of the recording. Omit the second argument, `autoStart`, to implicitly call `start` when the function is invoked. +Use recursion. +Provided that `running` is `true`, continue invoking `window.requestAnimationFrame()` which invokes the provided callback. +Return an object with two methods `start` and `stop` to allow manual control of the recording. +Omit the second argument, `autoStart`, to implicitly call `start` when the function is invoked. ```js const recordAnimationFrames = (callback, autoStart = true) => { @@ -28,9 +30,9 @@ const recordAnimationFrames = (callback, autoStart = true) => { ``` ```js -const cb = () => console.log('Animation frame fired') -const recorder = recordAnimationFrames(cb) // logs 'Animation frame fired' on each animation frame -recorder.stop() // stops logging -recorder.start() // starts again -const recorder2 = recordAnimationFrames(cb, false) // `start` needs to be explicitly called to begin recording frames +const cb = () => console.log('Animation frame fired'); +const recorder = recordAnimationFrames(cb); // logs 'Animation frame fired' on each animation frame +recorder.stop(); // stops logging +recorder.start(); // starts again +const recorder2 = recordAnimationFrames(cb, false); // `start` needs to be explicitly called to begin recording frames ```