Skip to content

Instantly share code, notes, and snippets.

View rndme's full-sized avatar

dandavis rndme

View GitHub Profile
// uses arrow functions to define methods seperatly from data, like an alternative to .prototype.
var x=function(){
return { // public methods:
get: ( )=> this.val,
set: (v)=> this.val=v,
};
}.call({ // private state:
val: 902
});
// uses arrow functions to define methods and creates an un-breakable bind to `this`
var x=new function(){
Object.assign(this, {
val : 530,
get: ( )=> this.val,
set: (v)=> this.val=v,
});
};
x.get(); // 530
<vcc-demo></vcc-demo>
<script src="http://danml.com/bundle/rndme.cia_rndme.vcc_.js"></script>
<script>
var store = CIA({
INC: function(state, n) {
state.index+= (n||1);
},
Object.defineProperty(window, "__", {set: Object.freeze});
// ex usage:
var state= __={
a: 1,
b: 3,
c: __=[1,2,3, __={ z: 7 } ]
};
// try to mutate:
@rndme
rndme / gist:f7242b26df5aeebcfa62
Created February 23, 2016 08:27
list of path and values of a deep object
function survey(object) {
function scan(ob, p, x) {
var k, v;
for(k in ob) {
if(!ob.hasOwnProperty(k)) continue;
v=ob[k];
if(typeof v === "object" && v && !+v) {
scan(v, p + "." + k, x);
} else {
function cache(size, duration) {
// an object cache, where you can set max size or time or both, and it maintains shit for you, and quickly too
var index = {}, stack = [],
count = 0;
size = size || 100;
duration = duration || 1000 * 60 * 5;
function add(key, val) {
count++;
var screenShotDialog = document.createElement("DIALOG");
document.body.appendChild(screenShotDialog).innerHTML="Hello World";
screenShotDialog.showModal();
var counter=1;
addEventListener("plus", function(e){
console.log(counter++);
});
dispatchEvent(new Event("plus"));
dispatchEvent(new Event("plus"));
dispatchEvent(new Event("plus"));
function ViewModel(rootElement){
rootElement = rootElement || document;
var model = Object.create(null);
function updateElement(elm){
var key = elm.getAttribute("bind"),
pre = elm.getAttribute("pre") || "",
function isSorted(arr, fn){
return !arr.some(function(a,b,c){
if(!b) return;
return fn(a, c[b-1])!==1;
});
}