Skip to content

Instantly share code, notes, and snippets.

View rupeshtiwari's full-sized avatar
🎯
Focusing

Rupesh Tiwari rupeshtiwari

🎯
Focusing
View GitHub Profile

Getting Started With Redux

There are 3 principle of redux

1st principle: ( One Application State )

  • Everything changes in application including data or ui change is placed in single object called state / state tree.

2nd Principle: ( Dispatch Action )

  • State tree is readonly. You can not modify or write. To change state dispatch actions.
  • State : minimumal representation of the data to the app.
const one = document.getElementById('one');
const two = document.getElementById('two');
const three = document.getElementById('three');
const f = R.curry((a,b,c)=>{
a.addEventListener(b, (event)=>{
event.target.style.backgroundColor= c;
});
});
const f = a => b => c => a+b+c;
const result = f(1)(2)(3);
console.log(result);
//---------------------------------------
const f = a => b => c => a+b+c;
const result = f(1)(2)(3);
console.log(result);
//---------------------------------------
const one = document.getElementById('one');
const two = document.getElementById('two');
const three = document.getElementById('three');
const f = a => b => c => a.addEventListener(b, (event)=>{
//-----COMPLETE_TODO------------
const stateBefore = {
todos: [{ text: 'testing', complete: false, path: ['todos', 0] }]
};
const stateAfter = {
todos: [{ text: 'testing', complete: true, path: ['todos', 0] }]
};
const result = over(lensPath(['todos',0, 'complete']), not, stateBefore);
console.log(result);
var a = {
selectedPath: [],
nodes: [{
title: 'core',
path:['nodes',0],
selected: false,
tabIndex: -1
},
{
title: 'core',
@rupeshtiwari
rupeshtiwari / selector-example-2.ts
Last active September 1, 2017 20:45
Reselect Selector example for the form control. Validating a Form which has many fields using Reselect Selectors.
const {
createSelector
} = Reselect;
const form = {
firstName: 'Rakesh',
lastName: 'Tiwari',
age: 12,
height: 157
};
@rupeshtiwari
rupeshtiwari / selector-example1.ts
Last active September 1, 2017 20:21
Reselect selector example for post object
// Code goes here
const {createSelector} = Reselect ;
const state = {
posts: [
{
title:'testing',
id: 1
},
{
@rupeshtiwari
rupeshtiwari / redux-store.ts
Last active September 1, 2017 02:21
Redux Store Example
// Code goes here
const {
createStore
} = Redux;
const initialState = {
name: 'Rupesh'
};
@rupeshtiwari
rupeshtiwari / redux-state-with-selectors.ts
Last active September 1, 2017 17:05
Redux Store with Reselect Selector example
// redux store reselect example same idea can be implemented with ngrx store/platform also.
// importing createStore
const {
createStore
} = Redux;
// importing of from rxjs
const {
of
} = Rx.Observable;