Skip to content

Instantly share code, notes, and snippets.

View toruticas's full-sized avatar

Rafael Mariano toruticas

View GitHub Profile
@toruticas
toruticas / dispatch.js
Created May 14, 2018 23:17
Redux simple explanation
store.dispatch({
type: 'OPEN_NFE_VISUALIZATION',
accessKey: 123
})
store.dispatch({
type: 'CLOSE_NFE_VISUALIZATION'
})
@toruticas
toruticas / reducer.js
Last active July 4, 2018 02:43
[Medium] Example of bad usage of redux
export default (action, state) => {
switch(action.type) {
case FIRST_EXAMPLE:
return {
...state,
quickbarIsOpen: true,
dfes: {
...state.dfes,
nfes: {
...state.dfes.nfes,
@toruticas
toruticas / reducer.js
Last active July 4, 2018 02:45
[Medium] reducer with ImmutableJS
export default (action, state) => {
switch(action.type) {
case FIRST_EXAMPLE:
return state
.updateIn(
["dfes", "nfes", "data", action.index],
data => data.set("visible", true)
)
.setIn("quickbarIsOpen", true)
@toruticas
toruticas / loader.js
Created August 13, 2018 13:18
Real world bug modifying reference argument in a function
import { init } from "@rematch/core"
import * as models from "./models"
import * as reducers from "./reducers"
import { syncInitialStatePlugin } from "./plugins"
function initStore(initialStateModel ,initialStateRedux) {
store = init({
models: models,
plugins: [syncInitialStatePlugin(initialStateModel)],
@toruticas
toruticas / reducer.js
Last active May 27, 2019 02:19
Redux Architecture Example (reducer)
import { List, Map } from 'immutable';
export const scaffold = Map({
currentIndex: 1,
inputValue: '',
items: List(),
});
export default (state = scaffold, action) => {
switch (action.type) {
@toruticas
toruticas / selectors.js
Created May 27, 2019 02:19
Redux Architecture Example (selectors)
export const getItems = state => state.get('items');
export const getInputValue = state => state.get('inputValue');
export const getCurrentIndex = state => state.get('currentIndex');
@toruticas
toruticas / actions.js
Created May 27, 2019 02:20
Redux Architecture Example (actions)
export const changeInputValue = value => ({
type: 'CHANGE_INPUT_VALUE',
value,
});
export const addItem = item => ({
type: 'ADD_ITEM',
item,
});
@toruticas
toruticas / creators.js
Created May 27, 2019 02:21
Redux Architecture Example (creators)
import { Map } from 'immutable';
import { getInputValue, getCurrentIndex } from './selectors';
import {
addItem as addItemAction,
changeInputValue,
} from './actions';
export const addItem = () => (dispatch, getState) => {
const state = getState();
@toruticas
toruticas / effects.js
Created May 27, 2019 02:22
Redux Architecture Example (effects)
export const localStorageSync = () => (_, getState) => {
const todos = getState().todos.toJS();
localStorage.setItem('redux-todos', JSON.stringify(todos));
};
@toruticas
toruticas / config.lua
Last active November 14, 2024 19:24
Neovim configs: ~/.config/nvim/*
local iron = require("iron.core")
local view = require("iron.view")
iron.setup {
config = {
-- Whether a repl should be discarded or not
scratch_repl = true,
-- Your repl definitions come here
repl_definition = {
sh = {