Skip to content

Instantly share code, notes, and snippets.

@julianburr
julianburr / suspense-content.js
Last active September 22, 2024 08:57
Minified bit of Javascript needed to allow out-of-order streaming
window.customElements.define('suspense-content', class SuspenseContent extends HTMLElement {
connectedCallback () {
// Assume previous sibling is the `<template>` element
const content = this.previousElementSibling.content;
// Get `target-id` from custom element attributes and find fallback placeholder based on it
const id = this.getAttribute('target-id');
const target = document.querySelector('[data-suspense-id="' + id + '"]');
// Replace fallback content with actual content
@julianburr
julianburr / IGNRW Crawler.md
Last active May 7, 2024 11:36
IGNRW Crawler
# Stell sicher dass du NodeJS installiert hast
# Siehe https://nodejs.org/en/learn/getting-started/how-to-install-nodejs

# Installier npm dependencies
npm install

# Beispiel script ausführung
LOGIN_USERNAME=foo LOGIN_PASSWORD=bar node index.mjs
@julianburr
julianburr / example.sh
Created March 23, 2021 12:08
Git - delete merged branches locally and remote
# https://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-have-been-merged
# Delete local branches that have been merged i.e. into "main"
git branch --merged main | grep -v "(^\*|main)" | xargs git branch -d
# Delete remote branches that have been merged i.e. into "main
git branch -r --merged main | grep -v "(^\*|main)" | sed 's/origin\///' | xargs -n 1 git push --delete origin
@julianburr
julianburr / workshop.md
Last active November 6, 2019 00:32
Model Generator Workshop

Model Generator Workshop

Model Generator was created to solve a bunch of core problems we had to deal with in regards to API data flows within our React apps. We wanted to use Redux (because it seemed the best solution to store the data at the time), but needed to address the following:

  1. Redux Boilerplate
  2. Data Fetching
  3. State Normalisation

1. Redux Boilerplate

@julianburr
julianburr / dumb-cache-provider.js
Last active January 20, 2019 12:17
Why Suspense Will Be a Game Changer - Dumbest Cache Provider Example
// Yep, we're doing it, just storing the data on a plain old object
let data = {};
export default (fetchFn, getKey = (x) => x) => (args) => {
// Get unique identifier from arguments
const key = getKey(args);
if (data[key]) {
if (typeof data[key].then === 'function') {
// Fetch has already been triggered
// So throw the stored promise instead of triggering another request
@julianburr
julianburr / suspense-boundaries.js
Last active August 27, 2019 09:48
Why Suspense Will Be a Game Changer - Suspense Boundaries
class App extends Component {
render () {
return (
<Suspense fallback={<p>Loading...</p>}>
<DeepNesting>
<ThereMightBeSeveralAsyncComponentsHere />
</DeepNesting>
</Suspense>
);
}
@julianburr
julianburr / concurrent-mode.js
Created January 20, 2019 02:46
Why ... - Concurrent mode
// Instead of this...
ReactDOM.render(<App />, document.getElementById('root'));
// ...we do this
ReactDOM.createRoot(document.getElementById(‘root’)).render(<App />);
@julianburr
julianburr / suspense.js
Last active January 29, 2019 09:37
Why Suspense Will Be a Game Changer - Suspense
import createResource from './magical-cache-provider';
const dataResource = createResource((id) => fetchData(id));
class DynamicData extends Component {
render () {
const data = dataResource.read(this.props.id);
return <p>Data loaded 🎉</p>;
}
}
@julianburr
julianburr / context.js
Last active August 27, 2019 09:45
Why Suspense Will Be a Game Changer - Context
const DataContext = React.createContext();
class DataContextProvider extends Component {
// We want to be able to store multiple sources in the provider,
// so we store an object with unique keys for each data set +
// loading state
state = {
data: {},
fetch: this.fetch.bind(this)
};
@julianburr
julianburr / local-state.js
Last active January 20, 2019 02:51
Why Suspense Will Be a Game Changer - Local State
class DynamicData extends Component {
state = {
loading: true,
error: null,
data: null
};
componentDidMount () {
fetchData(this.props.id)
.then((data) => {