Skip to content

Instantly share code, notes, and snippets.

var spec = { enumerable: false }
var x = {};
Object.defineProperty(x, "test", spec);
x.test = "what"
alert(JSON.stringify(x));
var y = {};
Object.defineProperty(y, "test", spec);
@jhusain
jhusain / Response
Created August 19, 2015 18:19
Games JSON Graph
//You shouldn't find your self asking for ids from a Falcor JSON Graph object.
//it seems like you want to build an array of game ids:
{
games: [
{ $type: "ref", value: ["gamesById", 352] },
{ $type: "ref", value: ["gamesById", 428] }
// ...
],
// mock falcor Model
function Model(root, path) {
this.root = root;
this.path = path || [];
}
Model.prototype.bind = function(path) {
return new Model(this.root, this.path.concat(path));
};
@jhusain
jhusain / gist:3c510869ec091772c440
Last active August 29, 2015 14:26
Observable map function
class Observable {
map(fn) {
if (typeof fn !== "function")
throw new TypeError(fn + " is not a function");
let C = this.constructor[Symbol.species];
return new C(observer => {
@jhusain
jhusain / gist:4b14f5069f3a254cfa0a
Created April 19, 2015 16:27
Converting event to Observable
function fromEvent(dom, eventName) {
return {
forEach: function(observer) {
var handler = (e) => {
observer.onNext(e);
};
dom.addEventListener(eventName, handler);
// Subscription
return {
@jhusain
jhusain / index.js
Created April 3, 2015 02:42
requirebin sketch
// When you click the button on the right, this program
// retrieves a stock quote from a stubbed method. If the
// button is clicked while a (stubbed/fake) network request
// is in-flight, then the fake request is cancelled and
// a new one is issued. To confirm this, press the button
// several times and notice that only one stock quote is
// returned.
var Task = require('task-lib');
var getQuoteButton = document.createElement('button');
@jhusain
jhusain / index.js
Created April 3, 2015 02:37
requirebin sketch
// When you click the button on the right, this program
// retrieves a stock quote from a stubbed method. If the
// button is clicked while a (stubbed/fake) network request
// is in-flight, then the fake request is cancelled and
// a new one is issued. To confirm this, press the button
// several times and notice that only one stock quote is
// returned.
var Task = require('task-lib');
var getQuoteButton = document.getElementById('getQuote');
@jhusain
jhusain / l
Created November 20, 2014 23:14
Iterable and Observable are dual
interface Iterable {
Generator @@iterator(Generator);
}
interface Observable {
Generator observer(Generator);
}
Array.prototype[@@observer] = function(generator) {
var decoratedGenerator = Object.create(generator),
@jhusain
jhusain / index.js
Created August 8, 2014 21:33
requirebin sketch
// example using the raf module from npm. try changing some values!
var Rx = require('rx');
window.Rx = Rx;
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),(f.falkor||(f.falkor={})).PathEvaluator=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
var Rx = _dereq_("../src/rx.ultralite");
var Observable = Rx.Observable,
Disposable = Rx.Disposable,
sentinelSize = 50,
isArray = Ar
/*
* Performs a exclusive map waiting for the first to finish before subscribing to another observable.
* Observables that come in between subscriptions will be dropped on the floor.
* @param {Function} selector Selector to invoke for every item in the current subscription.
* @param {Any} [thisArg] An optional context to invoke with the selector parameter.
* @returns {Observable} An exclusive observable with only the results that happen when subscribed.
*/
observableProto.exclusiveMap = function (selector, thisArg) {
var sources = this;
return new AnonymousObservable(function (observer) {