Skip to content

Instantly share code, notes, and snippets.

@Soreine
Soreine / SortingScreen.tsx
Last active May 7, 2020 10:13
Undo using Command pattern. The Command objects can be anonymous functions
// This is some pseudocode
function onArchiveAndNext(threadId) {
dispatch(archiveThread(threadId));
dispatch(sortingGoToNext(thread));
// We can define the undo logic right next to the effect to undo.
// This also means any part of the UI can define its own undoable effect.
@Soreine
Soreine / toValidateNode.js
Last active November 6, 2017 00:18
A function that convert an old Slate rule, to a single plugin object, containing the corresponding `validateNode` function
// Converts an old rule definition to an individual plugin with a "validateNode" function
//
// rule: {
// match,
// validate,
// normalize
// }
//
// returns {
// validateNode
@Soreine
Soreine / MultiHover.js
Created April 14, 2017 08:03
React - MultiHover
/* @flow */
import { Set } from 'immutable';
/*
* Hover state manager for multiple elements.
*
* Usage:
*
* onHoverChange callback is called whenever the mouse enter the group
@Soreine
Soreine / relativeOffset.js
Created December 14, 2016 12:21
Slate relative offset
/**
* Converts a {key, offset} combination to a single offset relative to
* `node`. `key` must be the key of one of the texts inside `node`.
*/
function relativeOffset(node, key, offset) {
return node
.getTexts()
.takeUntil(text => text.key === key)
.reduce((absOffset, text) => absOffset + text.length)
+ offset;
Benchmarks
delete-backward-deep
Current: 229 ops/sec (102 runs sampled)
Reference: 234 ops/sec (103 runs sampled)
comparison: Indeterminate
diff: -2.21%
rme: ±3.62%
delete-backward-normal
@Soreine
Soreine / README.adoc
Created June 29, 2016 12:44
A small FAQ template made with GitBook, theme-faq, and Asciidoc
index

This is the FAQ’s README and is not part of the generated book because we configured the book.json to use home.doc instead.

@Soreine
Soreine / index.html
Created May 24, 2016 09:52
DraftJS decorators issue
<!DOCTYPE html>
<html>
<head>
<!-- Immutable -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.1/immutable.js"></script>
<!-- React -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.1/react.js"></script>
<!-- ReactDOM -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.1/react-dom.js"></script>
<!-- Draft -->
@Soreine
Soreine / debounce.js
Last active February 22, 2016 13:04
A custom debouncing function
// Returns a function that can't be called more than once per `delay`,
// with a maximum delay of `maxDelay`. The returned function can be called
// forcefully through its `flush` property
function debounce(fn, delay, maxDelay) {
var timer;
var maxTimer;
var args;
var clearTimers = function () {
if (timer) clearTimeout(timer);
@Soreine
Soreine / disqus.html
Last active January 25, 2019 09:51
Jekyll include file to integrate disqus comments.
{% if site.disqus_short_name and page.comments != false %}
<div id="disqus_thread"></div>
<script>
var disqus_shortname = '{{ site.disqus_short_name }}';
var disqus_config = function () {
// _config.yml should define the site's URL
this.page.url = '{{ site.url }}{{ page.url }}';
// Using an optional disqus_identifier variable, or the site.url + page.id combination
this.page.identifier = '{% if page.disqus_identifier %}{{ page.disqus_identifier}}{% else %}{{ site.url }}{{ page.id }}{% endif %}';
};