Skip to content

Instantly share code, notes, and snippets.

View andrei-cacio's full-sized avatar
👀
🤔 👀

Andrei Cacio andrei-cacio

👀
🤔 👀
View GitHub Profile
@andrei-cacio
andrei-cacio / fetch-with-cookies.js
Last active December 30, 2017 17:38
Fetch credentials example
fetch('/api/v1/logout', {
credentials: 'same-origin'
});
@andrei-cacio
andrei-cacio / wwl2.js
Created January 13, 2017 14:16
What will log? Part II
console.log(1..toString());
@andrei-cacio
andrei-cacio / wwl.js
Last active January 13, 2017 11:40
What will log? Part I
var people = (function() {
var people = [];
render();
function render() {
var people = people;
console.log(people);
}
}())
@andrei-cacio
andrei-cacio / reducers.js
Last active October 21, 2016 08:49
Redux reducers refactored using ES2015 enhanced object literals
import { combineReducers } from 'redux';
import { LOGIN, LOGOUT } from './action-types';
const initialState = {};
const user = (state = initialState, action) => {
const actionTypeHandlerMap = {
[LOGIN]: ({ status, userInfo }) => ({ ...state, status, userInfo }),
[LOGOUT]: ({ status }) => ({ ...state, status, userInfo: {}}),
[undefined]: () => state
}
import $ from 'jquery';
export const isEmpty = value => !value.length;
export default function getValidator(rule, inputSelector, valueGetter) {
return {
validate() {
const $input = $(inputSelector);
const value = valueGetter();
import { assert } from 'chai';
import proxyquire from 'proxyquire';
import { getJquerySpies, getJquery } from '../src/jquery-getter';
const $ = getJquery();
const getValidator = proxyquire('../src/validator', { jquery : $ }).default;
const isEmpty = proxyquire('../src/validator', { jquery : $ }).isEmpty;
const addClassFn = getJquerySpies().addClass;
const sinon = require('sinon');
const fakeDOM = require('jsdom').jsdom();
let nodeJquery = null;
let jquerySpies = null;
export function getJquery() {
if (!nodeJquery) {
nodeJquery = require('jquery')(fakeDOM.defaultView);
}
import { View } from 'backbone';
import { getJquery }from './jquery-getter';
const $ = getJquery();
export class SimpleView extends View {
constroctor() {
super({ el: '#someDiv' });
}
const fakeDOM = require(‘jsdom’).jsdom(); 
nodeJquery = require(‘jquery’)(fakeDom.defaultView);
@andrei-cacio
andrei-cacio / jquery-getter.js
Last active June 12, 2016 09:33
jQuery getter function
let nodeJquery = null;
export function getJquery(spy = false) {
if (!nodeJquery) {
const sinon = require('sinon');
const fakeDOM = require('jsdom').jsdom();
nodeJquery = require('jquery')(fakeDOM.defaultView);
}
return nodeJquery;