This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function guid() { | |
function s4() { | |
return Math.floor((1 + Math.random()) * 0x10000) | |
.toString(16) | |
.substring(1); | |
} | |
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); | |
} | |
var defaultActionTypes = {add: null, remove: null, perform: null}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"auth": 1, | |
"users": { | |
1: {"username": "mattiamanzati", "token": "resthttprequestsaccesstoken"}, | |
2: {"username": "another user"} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getUsers = (state) => state.users; | |
const getLoggedUserId = (state) => state.auth; | |
const getLoggedUser = (state) => getUsers(state)[getLoggedUserId(state)]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Triggered whenever the user clicks the login submit button | |
export const LOGIN_SUBMIT = 'core_auth/LOGIN_SUBMIT'; | |
export function loginSubmit(data){ | |
return { | |
type: LOGIN_SUBMIT, | |
payload: data | |
}; | |
} | |
// Triggered whenever a login request is dispatched from whenever point in the code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {combineReducers} from 'redux'; | |
import {LOGIN_SUCCESS, LOGOUT} from './actions'; | |
function users(state = {}, action){ | |
if(!action) return state; | |
switch(action.type){ | |
case LOGIN_SUCCESS: | |
return { | |
...state, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {login} from './api'; | |
import {take, put, fork, call, race} from 'redux-saga/effects'; | |
import {LOGIN_REQUEST, LOGIN_SUBMIT, LOGIN_SUCCESS, LOGIN_ERROR} from './actions'; | |
import {loginRequest, loginError, loginSuccess} from './actions'; | |
import {startSubmit, stopSubmit} from '../form/actions'; | |
import {clearState} from '../router/actions'; | |
function* handleLoginSubmit(){ | |
// run the daemon | |
while(true){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {getLoggedUser} from './selectors'; | |
class LoggedUserName extends React.Component{ | |
render(){ | |
return this.props.user ? <p>{this.props.user.username}</p> : <p>Anonymous Cow</p>; | |
} | |
} | |
function mapStateToProps(state){ | |
return { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Observable, Subject} from 'rxjs'; | |
export const INCREMENT = 'INCREMENT'; | |
export const DECREMENT = 'DECREMENT'; | |
interface Model{ | |
value: number | |
} | |
interface Intent{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xs, {Stream} from 'xstream'; | |
import {DOMSource, input, span, div, VNode} from '@cycle/dom'; | |
export interface TextInputProps{ | |
value$?: Stream<string> | |
} | |
export interface TextInputSources{ | |
DOM: DOMSource | |
props?: TextInputProps |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xs, {Stream} from 'xstream'; | |
import {run} from '@cycle/xstream-run'; | |
import isolate from '@cycle/isolate'; | |
import TextInput, {TextInputComponent} from './ui/TextInput'; | |
import {makeDOMDriver, DOMSource, VNode, div} from '@cycle/dom'; | |
interface MainSources{ | |
DOM: DOMSource | |
} |