Skip to content

Instantly share code, notes, and snippets.

View ozcanzaferayan's full-sized avatar
⚛️
Overreacting

Özcan Zafer AYAN ozcanzaferayan

⚛️
Overreacting
View GitHub Profile
@ozcanzaferayan
ozcanzaferayan / LoginScreen.js
Created January 29, 2020 23:00
Mobx with functional component
import React from 'react';
import { Button, Text, SafeAreaView } from 'react-native';
import { observable } from 'mobx';
import { observer } from 'mobx-react';
const store = observable({ count: 0 });
const LoginScreen = observer(() => {
handleInc = () => store.count++;
handleDesc = () => store.count--;
import React from 'react';
import { Button, Text, SafeAreaView } from 'react-native';
import { observable } from 'mobx';
import { observer } from 'mobx-react';
@observer export class LoginScreen extends React.Component {
@observable count = 0;
handleInc = () => this.count++;
handleDesc = () => this.count--;
{
"presets": ["mobx"]
}
@ozcanzaferayan
ozcanzaferayan / index.js
Created January 27, 2020 21:46
redux-persist implementation
import React from 'react';
import { AppRegistry } from 'react-native';
import { StatusBar } from 'react-native';
import { name as appName } from './app.json';
import AppNavigator from 'containers/AppNavigator';
import { createAppContainer } from 'react-navigation';
import { store } from 'store';
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/integration/react'
import { persistor } from 'store';
import React from 'react';
import { AppRegistry } from 'react-native';
import { StatusBar } from 'react-native';
import { name as appName } from './app.json';
import AppNavigator from 'containers/AppNavigator';
import { createAppContainer } from 'react-navigation';
import { store } from 'store';
import { Provider } from 'react-redux';
StatusBar.setBarStyle('light-content', true);
import React, { useEffect } from 'react';
import { View, Text, TouchableOpacity, Image, FlatList, StyleSheet, RefreshControl } from 'react-native';
import images from 'res/images';
import colors from 'res/colors';
import palette from 'res/palette';
import MessageListItem from './MessageListItem';
import SearchBar from './SearchBar';
import { connect } from 'react-redux';
import { loadMessages } from 'actions';
@ozcanzaferayan
ozcanzaferayan / index.js
Last active January 27, 2020 20:37
sagas directory
import { put, fork, select, all, take, call } from 'redux-saga/effects'
import { getMessages } from 'reducers/selectors'
import { api } from 'services'
import { messages, LOAD_MESSAGES } from 'actions'
function* fetchEntity(entity, apiFn, id) {
yield put( entity.request(id) )
const {response, error} = yield call(apiFn, id)
if(response)
yield put( entity.success(id, response) )
@ozcanzaferayan
ozcanzaferayan / index.js
Last active January 27, 2020 20:11
store directory
import { createStore, applyMiddleware } from 'redux';
import rootReducer from 'reducers';
import logger from 'redux-logger';
import createSagaMiddleware from 'redux-saga';
import rootSaga from 'sagas';
const sagaMiddleware = createSagaMiddleware();
sagaMiddleware.run(rootSaga);
export const store = createStore(rootReducer, applyMiddleware(sagaMiddleware, logger));
@ozcanzaferayan
ozcanzaferayan / index.js
Created January 27, 2020 19:53
reducers directory
import { combineReducers } from 'redux'
import { merge } from 'lodash/object'
function entities(state = { messages: {} }, action) {
if (action.response && action.response.entities) {
return merge({}, state, action.response.entities)
}
return state
}
@ozcanzaferayan
ozcanzaferayan / index.js
Last active January 27, 2020 19:48
schemas directory
import { schema } from 'normalizr'
const messageSchema = new schema.Entity('messages', {}, {
idAttribute: 'key',
});
export const responseMessageSchema = { messages: new schema.Array(messageSchema) };