Skip to content

Instantly share code, notes, and snippets.

View gilankpam's full-sized avatar
🏸
Focusing

Gilang gilankpam

🏸
Focusing
View GitHub Profile
import { createStore, applyMiddleware } from 'redux'
import reducers from './reducers'
import myMiddleware from './middleware'
const store = createStore(reducers, applyMiddleware(myMiddleware))
import loginReducer from './login'
import registerReducer from './register'
import productReducer from './product'
import { combineReducers } from 'redux'
export default combineReducers ({
login: loginReducer,
register: registerReducer,
product: productReducer
export const { loginAction, loginActionTypes, loginReducer } = reduxHelper('login', function(username, password) {
return api.login('username', 'password')
})
function middleware({dispatch}) {
return next => action => {
if (typeof action === 'function') {
return action(dispatch)
}
return next(action)
}
}
// we are not using arrow function, because there no arguments binding
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions
function action() {
const args = arguments
return dispatch => {
dispatch({
type: actionRequest
})
try {
const result = fn.apply(this, args)
const actionRequest = actionName + '_REQUEST'
const actionSuccess = actionName + '_SUCCESS'
const actionFailure = actionName + '_FAILURE'
const initialState = {
data: null,
loading: false,
error: null
}
function login(username, password) {
return dispatch => {
dispatch({
type: 'LOGIN_REQUEST'
})
api.login(username, password)
.then(user => dispatch({
type: 'LOGIN_SUCCESS',
user
}))
const initialState = {
loading: false,
user: null,
error: null
}
export default function (state = initialState, action) {
switch(action.type) {
case 'LOGIN_REQUEST':
return {
@gilankpam
gilankpam / redux-request-success-failure.js
Last active May 17, 2022 14:04
redux-request-success-failure.js
function reduxHelper (actionName, fn) {
if (typeof actionName !== 'string') {
throw new Error('actionName must be a string')
}
if (typeof fn !== 'function') {
throw new Error('fn must be a function')
}
const actionNameUpper = actionName.toUpperCase()
const actionRequest = actionNameUpper + '_REQUEST'
const actionSuccess = actionNameUpper + '_SUCCESS'
@gilankpam
gilankpam / multimedia.ahk
Created April 16, 2017 10:53
AutoHotKey for multimedia shortcut
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
^f9::Send {Media_Prev}
^f10::Send {Media_Next}
^f11::Send {Volume_Down}
^f12::Send {Volume_Up}