Skip to content

Instantly share code, notes, and snippets.

@andon
andon / fetch-with-revalidate.js
Created January 9, 2018 23:04
Fetch with client revalidation. On failure performs another fetch without client revalidation, so that you get cached result if available.
const doFetch = (url, opts = {}) => {
const headers = new Headers()
headers.append('Cache-Control', 'max-age=0')
if (opts.headers) {
for (const header of opts.headers) {
headers.append(header[0], header[1])
}
}
return new Promise((resolve, reject) => {
fetch(url, {
@andon
andon / MainReactPackageWithHttpCache.java
Created January 9, 2018 21:31
Implementation of MainReactPackage thats creates a custom NetworkingModule that configures an HTTP cache.
package com.cachetester;
import com.facebook.react.bridge.ModuleSpec;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.modules.network.NetworkingModule;
import com.facebook.react.modules.network.OkHttpClientProvider;
import com.facebook.react.shell.MainReactPackage;
import java.io.File;
@andon
andon / app-with-perfmonitor.js
Last active May 28, 2017 08:39
Enable PerfMonitor in react-native app
import PerfMonitor from 'react-native/Libraries/Performance/RCTRenderingPerf';
PerfMonitor.toggle();
PerfMonitor.start();
class App extends Component {
componentDidMount() {
setTimeout(() => {
PerfMonitor.stop();
}, 8000);
}
@andon
andon / rn-cli.config.js
Created January 17, 2016 18:19
Custom rn-cli configuration that configures project roots for React Packager
'use strict';
var path = require('path');
var config = {
getProjectRoots() {
return getRoots();
},
getAssetRoots() {