Skip to content

Instantly share code, notes, and snippets.

@atafs
atafs / saga-effect-takeEvery.js
Created June 5, 2018 21:35
Saga Effect Take Every
// 1
let process = function*() {
while(true) {
console.log("Process loop.")
yield delay(1000)
}
}
// 2
let saga = function*() {
@atafs
atafs / saga.spec.js
Created June 4, 2018 10:25
Testing with Jest for Actions and Reducer
import {
call,
take
} from 'redux-saga'
import { reducer } from '../../Reducer/index'
import * as ChatActions from "../../Actions";
// dummy data
const previousState = {
@atafs
atafs / saga-effect-fork.js
Created May 23, 2018 19:10
Saga Effect Fork
// 1
function* fn() {
while(true) {
console.info('FN!');
yield delay(1000);
}
}
// 2
let forkSaga = function*() {
@atafs
atafs / saga-effect-call.js
Created May 23, 2018 19:00
Saga Effect Call
// 1
let fn = () => {
console.log('Called the function!!')
}
// 2
let callSaga = function*() {
yield fn();
}
@atafs
atafs / saga-effect-put.js
Last active May 23, 2018 19:21
Saga Effect Put
// 1
let mySaga = function*() {
console.info('Saga begins!!');
const state = yield effects.take('SET_STATE');
console.info('Got state...', state);
}
// 2
run(mySaga);
@atafs
atafs / saga-effect-take.js
Last active May 23, 2018 18:36
Saga Effect: Take
// run in the console of sandbox
// 1
effects.take('MY_ACTION');
// 2
let mySaga = function*() {
console.info('Saga begins!!');
const state = yield effects.take('SET_STATE');
console.info('Got state...', state);
@atafs
atafs / generator-start.js
Last active May 20, 2018 07:07
Redux Saga
// create a generator function
let generator = function*() {
return 5
}
let obj = generator()
obj.generator().next()
// iterate throught it
generator = function*() {
yield 1;
@atafs
atafs / jestdescr.js
Last active March 27, 2018 19:31
JS WebStorm IDE snippets: code to use as alias for more productivity
// jestdescr
// Inserts describe() block
describe('$NAME$', function() {
$END$
});
@atafs
atafs / js-redux-playground.js
Last active March 23, 2018 16:27
Redux way of managing state of the app (store)
// open the dev environment
// https://stephengrider.github.io/JSPlaygrounds/
// create reducer (function)
const reducer = (state = [], action) => {
if (action.type === 'SPLIT_STRING') {
return action.payload.split('');
} else if (action.type === 'ADD_CARACTER') {
// DO NOT MUTATE DATA IN A REDUCER
//state.push(action.payload);
@atafs
atafs / vagrant-provisioning-on-premise-demo01-create-vm.sh
Last active March 8, 2018 14:16
DevOps provisioning with vagrant to build virtual machines for testing code
#!/bin/bash
# install wget, virtualbox and vagrant
brew install wget
# enable in mac preferences to run oracle vm: https://developer.apple.com/library/content/technotes/tn2459/_index.html
brew cask install --force virtualbox
brew cask install vagrant
brew cask install vagrant-manager
# get a fresh Ubuntu 14.04 machine running and create a Vagrantfile