Skip to content

Instantly share code, notes, and snippets.

@mbret
mbret / App.tsx
Last active May 12, 2021 20:40
recoil persistance/restoration
import React from 'react'
import { PersistedRecoilRoot } from './PersistedRecoilRoot'
const myState = atom({ key: '...', default: ... })
const statesToPersist = [
myState
]
export const App = () => {
// we have a LOGOUT action that will reset the whole state
// HACK: When state is recreated, it will loose '_persist' in it, and the state will not be persisted anymore.
// Dispatching 'persist/REHYDRATE' makes persistence work again somehow, so we dispatch it to all persisted keys.
const storageKeys = yield call(storage.getAllKeys);
const persistKeys = (storageKeys.map((key: string) => {
const regexp = new RegExp('^persist:(.+)');
if (key.match(regexp)) {
return RegExp.$1;
}
@mbret
mbret / metro.config.js
Last active October 1, 2019 16:06
Symlink for React Native 0.59 (symlink + scoped package + hast name collision)
/**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* @format
*/
const {
getSymLinkedModules,
getBlacklistedModulesForAlternateRoot,
getExtraModulesForAlternateRoot,
@mbret
mbret / Text.js
Last active July 4, 2018 07:40
Text.js
/**
* @flow
*/
import React, { PureComponent } from 'react'
import { Text as NativeText, StyleSheet } from 'react-native'
import * as shared from 'cugn-vost-shared'
import { Theme } from '../../design'
import { createStyleSelector } from '../../services/style-helpers'
import type { c } from 'react'
import { i18n } from '../lang'
import {withAuthorization} from 'with-auth'
class MyProtectedComponent extends Component {
render () {
<View>...</View>
}
}
export default withAuthorization(MyProtectedComponent)
@mbret
mbret / App.js
Last active June 27, 2018 19:52
Helper to help deal with StyleSheet in React Native
/**
* @flow
*/
import React, { Component } from 'react'
import { StyleSheet, Text } from 'react-native'
import { MyCustomText } from './MyCustomText'
export class App extends Component {
render () {
return (
/**
* @flow
*/
import React from 'react'
import { AsyncStorage } from 'react-native'
import { connect } from 'react-redux'
import { RNDevToolbox } from 'rn-dev-toolbox'
import { isAuthenticated, getCurrentUser } from 'cugn-vost-shared/dist/flux/selectors'
import faker from 'faker'
import { store } from '../../redux/store'
import {setTransform, ReactNativeFile} from 'shared'
setTransform(file => new ReactNativeFile(file))
@mbret
mbret / combineAndIsolateReducers.js
Last active April 5, 2018 21:07
helper to use reduceReducers with combined reducers
import { combineReducers } from 'redux'
import reduceReducer from 'reduce-reducers'
const combineAndIsolateReducers = (reducers) => {
const keys = Object.keys(reducers)
const combined = combineReducers(reducers)
return (state = undefined, action) => {
// Important -> slice the needed state so it avoid combineReducers warnings
const sliced = {}
@mbret
mbret / index.html
Last active March 29, 2018 14:27
Angularjs one way binding
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.js"></script>
<style type="text/css">
</style>
<title>Angular: true one way binding</title>
</head>
<body>