// This is an advanced example! It is not typically required for application code. | |
// If you are using a library like Redux or MobX, use the container component provided by that library. | |
// If you are authoring such a library, use the technique shown below. | |
// This example shows how to safely update subscriptions in response to props changes. | |
// In this case, it is important to wait until `componentDidUpdate` before removing a subscription. | |
// In the event that a render is cancelled before being committed, this will prevent us from unsubscribing prematurely. | |
// We also need to be careful about how we handle events that are dispatched in between | |
// `getDerivedStateFromProps` and `componentDidUpdate` so that we don't put stale values into the `state`. |
<!-- refer generated css/js file --> | |
<link rel="stylesheet" href="{{$.Site.BaseURL}}/{{ if eq (getenv "APP_ENV") "dev" }}main.css{{ else }}{{ index .Site.Data.manifest "main.css" | relURL }}{{ end }}"> | |
<script type="text/javascript" src="{{$.Site.BaseURL}}/{{ if eq (getenv "APP_ENV") "dev" }}main.js{{ else }}{{ index .Site.Data.manifest "main.js" | relURL }}{{ end }}"></script> |
In 2017, Chrome, Firefox and Safari added support for passive event listeners. They help to make scrolling work smoother and are enabled by passing {passive: true}
into addEventListener()
.
The explainer mentions that passive: true
works for wheel and touch events. I practically analyzed when passive: true
actually helps:
Event | Works better with passive: true |
Is passive by default |
---|---|---|
wheel ¹ |
Yes (Chrome), No (Firefox) | No (Chrome), No (Firefox) |
touchstart |
Yes (Chrome), ?² (Firefox) | Yes (Chrome), ?² (Firefox) |
<?php | |
namespace App\Jobs; | |
use Illuminate\Queue\InteractsWithQueue; | |
use Illuminate\Support\Facades\Cache; | |
abstract class DebouncedJob extends Job { | |
use InteractsWithQueue; |
#!/usr/bin/env php | |
<?php | |
echo "Running tests.. "; | |
exec('vendor/bin/phpunit', $output, $returnCode); | |
if ($returnCode !== 0) { | |
// Show full output | |
echo PHP_EOL . implode($output, PHP_EOL) . PHP_EOL; | |
echo "Cannot push changes untill tests are OK.." . PHP_EOL; | |
exit(1); | |
} |
I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.
I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.
Chrome 51 has some pretty wild behaviour related to console.log
in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.
<?php | |
namespace App\Support\Jobs; | |
use Illuminate\Contracts\Queue\ShouldQueue; | |
class DebouncedJob implements ShouldQueue | |
{ | |
use \Illuminate\Foundation\Bus\DispatchesJobs; | |
use \App\Support\Cache\PrefixedCache; |
- Open Automator | |
- File -> New -> Service | |
- Change "Service Receives" to "files or folders" in "Finder" | |
- Add a "Run Shell Script" action | |
- Change "Pass input" to "as arguments" | |
- Paste the following in the shell script box: open -n -b "com.microsoft.VSCode" --args "$*" | |
- Save it as something like "Open in Visual Studio Code" |
export const Spring = (x, y, mass, stiffness, viscosity) => ({ | |
prevX: x, | |
prevY: y, | |
currX: x, | |
currY: y, | |
mass, stiffness, viscosity | |
}); | |
Spring.copy = (spring) => ({ | |
prevX: spring.prevX, |