function mapValues(obj, fn) { | |
return Object.keys(obj).reduce((result, key) => { | |
result[key] = fn(obj[key], key); | |
return result; | |
}, {}); | |
} | |
function pick(obj, fn) { | |
return Object.keys(obj).reduce((result, key) => { | |
if (fn(obj[key])) { |
###Fluid properties (via)
@mixin fp($property, $min, $max, $start: 320, $end: breakpoint('desktop'), $clip: true, $clipAtStart: true, $clipAtEnd: true) {
$start: $start / ($start * 0 + 1);
$end: $end / ($end * 0 + 1);
$multiplier: ($max - $min) / ($end - $start) * 100;
$adder: ($min * $end - $max * $start) / ($end - $start);
$formula: calc(#{$multiplier + 0vw} + #{$adder + 0px});
@if $clip and $clipAtStart {
@media (max-width: #{$start + 0px}) {
function debounce(callback, wait, immediate = false) { | |
let timeout = null | |
return function() { | |
const callNow = immediate && !timeout | |
const next = () => callback.apply(this, arguments) | |
clearTimeout(timeout) | |
timeout = setTimeout(next, wait) |
See also 📢 Dead simple tweetable JavaScript Emitter pattern module using Map (ES2015) which uses this package.
Browser compatibility (all)
Chrome* | Edge | FF | IE | Opera | Safari | iOS |
---|---|---|---|---|---|---|
38 | 12 | 13 | -* | 25 | 7.1 | 8 |
Notes:
/* | |
* Create an event emitter that goes like this | |
* emitter = new Emitter(); | |
* | |
* Allows you to subscribe to some event | |
* sub1 = emitter.subscribe('function_name', callback1); | |
* (you can have multiple callbacks to the same event) | |
* sub2 = emitter.subscribe('function_name', callback2); | |
* | |
* You can emit the event you want with this api |
See also 📰 Dead simple tweetable JavaScript PubSub pattern module using Set (ES2015) which this package uses.
Chrome* | Edge | FF | IE | Opera | Safari | iOS |
---|---|---|---|---|---|---|
38 | 12 | 13 | -* | 25 | 7.1 | 8 |
Notes:
# editorconfig.org | |
root = true | |
[*] | |
indent_style = space | |
indent_size = 2 | |
end_of_line = lf | |
charset = utf-8 | |
trim_trailing_whitespace = true | |
insert_final_newline = true |
How do you send information between clients and servers? What format should that information be in? What happens when the server changes the format, but the client has not been updated yet? What happens when the server changes the format, but the database cannot be updated?
These are difficult questions. It is not just about picking a format, but rather picking a format that can evolve as your application evolves.
By now there are many approaches to communicating between client and server. These approaches tend to be known within specific companies and language communities, but the techniques do not cross borders. I will outline JSON, ProtoBuf, and GraphQL here so we can learn from them all.
/* | |
* Implement the following classic FP functions using | |
* _only_ Array.prototype.{reduce|reduceRight}(). 🤓 | |
*/ | |
const filter = f => xs => xs | |
const map = f => xs => xs | |
const every = f => xs => xs |