Skip to content

Instantly share code, notes, and snippets.

View SathinduGA's full-sized avatar
💭
Eat | Sleep | Code

Sathindu SathinduGA

💭
Eat | Sleep | Code
View GitHub Profile
import { COUNTER_ADD, COUNTER_SUBTRACT } from "../actions/action_types";
const initialState = {
count: 0
};
const counterReducer = (state = initialState, action) => {
switch (action.type) {
case COUNTER_ADD:
return {
@SathinduGA
SathinduGA / rnredux_debug.js
Created September 9, 2018 15:17
Debug Integration
import { createStore, combineReducers, compose } from 'redux';
import counterReducer from './reducers/counter_reducer';
const rootReducer = combineReducers({
counter: counterReducer,
});
let composeEnhancers = compose;
if(__DEV__){
import { createStore, combineReducers } from 'redux';
import counterReducer from './reducers/counter_reducer';
const rootReducer = combineReducers({
counter: counterReducer,
});
const configStore = () => {
return createStore(rootReducer);
};
import React from 'react'; // Remember to import React
import { AppRegistry } from 'react-native';
import { Provider } from 'react-redux';
import {name as appname} from './app.json';
import Application from './src/app';
import configStore from './src/store/config_store';
const store = configStore();
@SathinduGA
SathinduGA / rnredux_action_types.js
Last active September 10, 2018 15:12
Action Types
export const COUNTER_ADD = 'COUNTER_ADD';
export const COUNTER_SUBTRACT = 'COUNTER_SUBTRACT';
import { COUNTER_ADD, COUNTER_SUBTRACT } from "./action_types";
export const counterAdd = () => {
return {
type: COUNTER_ADD
};
}
export const counterSubtract = () => {
return {
@SathinduGA
SathinduGA / rnredux_actions_index.js
Last active September 10, 2018 15:10
Actions Index
export { counterAdd, counterSubtract } from './counter_actions';
@SathinduGA
SathinduGA / rnredux_component_counter.js
Last active September 10, 2018 11:47
Counter Component
import React, { Component } from "react";
import { View, Text, StyleSheet } from "react-native";
import { connect } from "react-redux";
class CounterComponent extends Component {
constructor(props) {
super(props);
this.state = {};
}
@SathinduGA
SathinduGA / rnredux_main_screen.js
Last active September 10, 2018 15:09
Main Screen
import React, { Component } from 'react';
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
import { connect } from 'react-redux';
import { counterAdd, counterSubtract } from '../store/actions/index';
import CounterComponent from '../components/counter';
class MainScreen extends Component {
@SathinduGA
SathinduGA / rnredux_file_structure
Created September 9, 2018 16:48
File Structure
src
|_components
| |_counter.js
|
|_screens
| |_main_screen.js
|
|_store
|_actions
| |_action_types.js