Skip to content

Instantly share code, notes, and snippets.

View vitalipe's full-sized avatar

Vitali Perchonok vitalipe

View GitHub Profile
var state = mobx.observable({
todos : [],
visibilityFilter : "ALL",
addTodoItem : action(function (text, completed) {
this.todos.push({text, completed})
}),
setVisibilityFilter : action(function (filter) {
this.visibilityFilter = filter;
// calling this version of bind inside .render() should only create each bound function once
// WARNING: I didn't even ran this code :P so I'm not sure if it works
const _cache = new WeakMap();
const _cmpArray = (arr1, arr2) => (arr1.length === arr2.length) &&
(arr1.every((v,i)=> (v === arr2[i])));
function bind(fn, context, ...args) {
@vitalipe
vitalipe / Router.js
Created March 17, 2017 09:43
the-only-router-I-ever-needed
const _ = require("lodash");
const Navigo = require("navigo");
class Router {
constructor(routes, config) {
let handler = config.handler || (() => null);
let before = config.before || ((d) => d());
let router = new Navigo(null, true);
_(routes).each(
@vitalipe
vitalipe / get-in.js
Created October 11, 2016 01:13
get-in form clojure in JS
// returns the value in a nested associative structure,
// just like (get-in) in clojure
var getIn = function (obj, path) {
if (!_(path).isArray()) // normalize
path = _(arguments).toArray().rest().value();
if (path.length === 0)
return obj;
if (!_(obj).has(_.first(path)))
class SimpleAssetManager {
// loader is the function that will actually do the fetching & return a promise...
constructor(loader, options = {}) {
this._cache = {};
this._cacheLimit = (options.cacheLimit || 1000);
this._cacheTTL = (options.cacheTTL || 10*1000); // ms
this._taskLimit = (options.tasks || 4);
this._loader = loader;