Skip to content

Instantly share code, notes, and snippets.

@johanobergman
johanobergman / migrate-to-tiptap-format.js
Last active December 26, 2023 11:45
Migrate html to a more TipTap-friendly structure
/**
* Modifies legacy html to match TipTap document structure,
* without losing content.
*
* Images in paragraphs, links with images inside,
* links not in paragraphs and YouTube videos
* are taken care of.
*
* Images are assumed to be configured as blocks in TipTap.
@johanobergman
johanobergman / Info.md
Last active November 8, 2016 09:53
Remember the rangeBehaviors of a Relay connection

To remember a connection, run RangeBehaviors.remember in relay.prepareVariables with a name, the connection arguments and an optional rangeBehavior operation:

prepareVariables(variables) {
    var { startDate, endDate } = variables;

    RangeBehaviors.remember('items', { startDate, endDate }, 'prepend'); // append if not specified

    return variables;
}
@johanobergman
johanobergman / 1. Info.md
Last active February 7, 2019 21:01
Laravel-style DI in JavaScript

Laravel-style DI in JavaScript

Honestly, coming from PHP, I really don't like the way dependencies are handled in JavaScript. Using require() or import either gives me a singleton object, or a class that I have to instantiate myself.

The DI container in Laravel is wonderful, and allows you to basically just ask for a dependency in a class constructor and it hands it to you. You can bind things to the container, but you can also resolve things without explicitly binding them, which I think is awesome.

@johanobergman
johanobergman / 1. description.txt
Last active September 29, 2015 22:37
Sections in Ember.js components.
Simply register the two helpers "section" and "yield-section", and start right away!
See example below, using ember-cli: