Skip to content

Instantly share code, notes, and snippets.

View lithin's full-sized avatar

Anna Doubkova lithin

View GitHub Profile
@lithin
lithin / machine.js
Last active June 17, 2019 16:20
State machine discovering devices
const states = {
DISCOVERY: 'DISCOVERY',
GET_STARTED: 'GET_STARTED',
RENAME: 'RENAME',
TIMEOUT: 'TIMEOUT',
DONE: 'DONE',
ERROR: 'ERROR',
};
@lithin
lithin / state-machine.js
Created May 30, 2019 15:33
Example of react state machine with hooks
// @flow
import * as React from 'react';
import { Machine, interpret } from 'xstate';
import { Discovery } from '~/screens/install-devices/discovery';
import { GetStarted } from '~/screens/install-devices/get-started';
import { RenameDevice } from '~/screens/install-devices/rename-device';
import { mapping, type Props as ConnectorProps } from '~/core/domains/installation/devices/mappings';
import { hiveNavigate } from '~/navigation';
@lithin
lithin / notes.md
Last active May 30, 2019 19:44
Working on CLI
  1. Check out react-native repo and update template following Christoph's instructions

  2. Check out react-native-cli repo, cd into it and run yarn and yarn build.

  3. Go back up and create a new RN project: node ./cli/packages/cli/build/index.js init --template=file:///Users/annadoubkova/Workspace/react-native RNTestProject

  4. Update gradle config in the newly created project following the second part of Christoph's instructions

  5. Run start command REACT_NATIVE_APP_ROOT=../cli node ../cli/packages/cli/build/index.js start

@lithin
lithin / MainApplication.java
Created April 17, 2019 06:27
Lazy loading native modules
protected List<ReactPackage> getPackages() {
List<ReactPackage> packages = new ArrayList<>(Arrays.asList(
new MainReactPackage(),
));
packages.add(new LazyReactPackage() {
@Override
protected List<ModuleSpec> getNativeModules(ReactApplicationContext reactContext) {
return Arrays.asList(
ModuleSpec.nativeModuleSpec(
ReactNativeFingerprintScannerModule.class,
# serverless.yml
service:
name: beekeeper-serverless
frameworkVersion: 1.23.0
plugins:
- serverless-plugin-split-stacks
- serverless-plugin-custom-roles
import createLogger from 'redux-mori/dist/createLogger';
import { createStore } from 'redux-mori';
import { applyMiddleware } from 'redux';
const middlewares = [];
if (isDev) {
// you can extend logger options as usual but don’t have to
const logger = createLogger({
predicate: (getState, action) => !/EFFECT_/.test(action.type),
});
middlewares.push(logger);
// just import the same function from a different library
import { combineReducers } from 'redux-mori';
import userReducer from 'app/containers/User/reducer';
export default combineReducers({
user: userReducer
});
import React, { PropTypes } from 'react';
import { toJs } from 'mori';
import { connect } from 'react-redux';
// write this as a class component to leverage immutability of props for shouldComponentUpdate
const UserComponent = props => {
const user = toJs(props.user);
return (<div>Hi {user.name}!</div>);
}
import React, { PropTypes } from 'react';
import { toJs } from 'mori';
import { connect } from 'react-redux';
// write this as a class component to leverage immutability of props for shouldComponentUpdate
const UserComponent = props => {
const user = toJs(props.user);
return (<div>Hi {user.name}!</div>);
}
import { hashMap, merge } from 'mori';
import { USER_LOADED } from './actions';
// note that our default state is an empty hashMap - but it can be initialised into any hashMap
export default function userReducer(state = hashMap(), action) {
switch (action.type) {
case USER_LOADED:
return merge(state, action.user);
default:
return state;