Skip to content

Instantly share code, notes, and snippets.

@Gethyl
Gethyl / Calculator.js
Last active January 23, 2017 04:20
The Main and Calculator component used to explain Virtual DOM
import React from "react"
import ReactDOM from "react-dom"
export default class Calculator extends React.Component{
constructor(props) {
super(props);
this.state = {output: ""};
}
render(){
@Gethyl
Gethyl / applyMiddleware.js
Created January 16, 2017 04:11
Understanding redux-thunk
//compose from redux/compose.js
function compose(...funcs) {
console.info("$$$ compose function ")
console.dir( funcs)
if (funcs.length === 0) {
return arg => arg
}
if (funcs.length === 1) {
return funcs[0]
@Gethyl
Gethyl / createThunkMiddleware.js
Created January 16, 2017 04:10
Understanding redux-thunk
// createThunkMiddleware from redux-thunk.js
export function createThunkMiddleware(extraArgument) {
return function thunkFunction ({ dispatch, getState }) {
return function nextFunction (next) {
console.info("In next function")
console.dir(next)
return function actionFunction (action) {
console.info("action RETURNED")
console.dir(action)
@Gethyl
Gethyl / sagas.js
Created January 10, 2017 07:08
FirstReduxSagaExample/src/js/sagas/sagas.js
import {takeEvery,delay} from 'redux-saga'
import {call, put, take} from 'redux-saga/effects'
import {asyncTestInitial,asyncTestSaga,asyncFetchInitial,
asyncFetchSuccess,asyncFetchError} from '../actions/middlewareActions'
export function FetchTestData(){
return fetch('testdata.json')
.then((res)=> res.json())
.then((jsondata)=> {
//*******************************************************************************************************
describe('>>>H O M E --- REACT-REDUX (Mount + wrapping in <Provider>)',()=>{
const initialState = {output:10}
const mockStore = configureStore()
let store,wrapper
beforeEach(()=>{
store = mockStore(initialState)
wrapper = mount( <Provider store={store}><ConnectedHome /></Provider> )
})
//*******************************************************************************************************
describe('>>>H O M E --- REACT-REDUX (Shallow + passing the {store} directly)',()=>{
const initialState = {output:100}
const mockStore = configureStore()
let store,container
beforeEach(()=>{
store = mockStore(initialState)
container = shallow(<ConnectedHome store={store} /> )
})
@Gethyl
Gethyl / dumbHomeComponent.js
Created January 5, 2017 18:11
Dumb Component Home.js testing.
*********************************
describe('>>>H O M E --- Shallow Render REACT COMPONENTS',()=>{
let wrapper
const output = 10
beforeEach(()=>{
wrapper = shallow(<Home output={output}/>)
})
@Gethyl
Gethyl / schema.js
Created December 28, 2016 05:12
graphql schema
import {
GraphQLObjectType,
GraphQLNonNull,
GraphQLSchema,
GraphQLString,
GraphQLList,
GraphQLInt,
GraphQLBoolean
} from 'graphql/type';
import React from "react";
import ReactDOM from "react-dom";
import {DeleteItem, EditIconClicked, EditItem, CompleteItem} from "../../Actions/ToDoActions";
import Redux from "redux";
import { connect} from "react-redux";
import Grid from 'react-bootstrap/lib/Grid';
import Row from 'react-bootstrap/lib/Row';
import Col from 'react-bootstrap/lib/Col';
import ListGroup from 'react-bootstrap/lib/ListGroup';
import React from "react";
import ReactDOM from "react-dom";
import {DeleteItem, EditIconClicked, EditItem, CompleteItem} from "../../Actions/ToDoActions";
import Redux from "redux";
import { connect} from "react-redux";
import Grid from 'react-bootstrap/lib/Grid';
import Row from 'react-bootstrap/lib/Row';
import Col from 'react-bootstrap/lib/Col';
import ListGroup from 'react-bootstrap/lib/ListGroup';