UNPKG

datastore

Version:

> [Brick](http://github.com/bredele/brickjs) reactive data layer

13 lines (12 loc) 3.83 kB
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.datastore = f()}})(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);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.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(require,module,exports){ var promise=require("bluff"),delegate=require("./lib/adapter"),Emitter=require("emitter-component");module.exports=function(e,t){e=e||{};var n=new Emitter,r=delegate(n,e,t);return n.get=function(t){return e[t]},n.pull=function(e){return promise(function(t){r("pull",t,e)})},n.set=function(t,i){var u=e[t],o=function(e){return promise(function(o){r("set",function(e,t){o(t),n.emit("changed "+e,i,u),n.emit("changed",e,i,u)},t,e)})};return null==i?o:o(i)},n.del=function(t){var i=e[t];return promise(function(e){r("del",function(r){e(r),n.emit("deleted "+t,i),n.emit("deleted",t,i)},t)})},n}; },{"./lib/adapter":2,"bluff":4,"emitter-component":5}],2:[function(require,module,exports){ var memory=require("./memory");module.exports=function(r,n,o){var e=memory.call(r,n);return o=o?o.call(r,n):{},function(r,n,m,u){(o[r]||function(r,n,o){r(n,o)})(function(o,m){e[r](n,o,m)},m,u)}}; },{"./memory":3}],3:[function(require,module,exports){ module.exports=function(n){return{set:function(t,e,o){n[e]="function"==typeof o?o.call(n):o,t(e,o)},del:function(t,e){delete n[e],t(e)},pull:function(t,e){t(n[e])}}}; },{}],4:[function(require,module,exports){ module.exports=function n(t){var u,f="pending",c=[],i=[];return t(function(n){f="fulfilled",u=n,c.map(function(n){n(u)})},function(n){f="rejected",u=n,i.map(function(n){n(u)})}),{then:function(t,o){return"function"!=typeof t&&(t=function(n){return n}),"function"!=typeof o&&(o=function(n){return n}),n(function(n,e){"pending"==f?(c.push(function(u){try{n(t(u))}catch(n){e(n)}}),i.push(function(n){try{e(o(n))}catch(n){e(n)}})):"fulfilled"==f?n(t(u)):e(o(u))})}}}; },{}],5:[function(require,module,exports){ function Emitter(t){if(t)return mixin(t)}function mixin(t){for(var e in Emitter.prototype)t[e]=Emitter.prototype[e];return t}module.exports=Emitter,Emitter.prototype.on=Emitter.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks[t]=this._callbacks[t]||[]).push(e),this},Emitter.prototype.once=function(t,e){function i(){r.off(t,i),e.apply(this,arguments)}var r=this;return this._callbacks=this._callbacks||{},i.fn=e,this.on(t,i),this},Emitter.prototype.off=Emitter.prototype.removeListener=Emitter.prototype.removeAllListeners=Emitter.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var i=this._callbacks[t];if(!i)return this;if(1==arguments.length)return delete this._callbacks[t],this;for(var r,s=0;s<i.length;s++)if(r=i[s],r===e||r.fn===e){i.splice(s,1);break}return this},Emitter.prototype.emit=function(t){this._callbacks=this._callbacks||{};var e=[].slice.call(arguments,1),i=this._callbacks[t];if(i){i=i.slice(0);for(var r=0,s=i.length;r<s;++r)i[r].apply(this,e)}return this},Emitter.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks[t]||[]},Emitter.prototype.hasListeners=function(t){return!!this.listeners(t).length}; },{}]},{},[1])(1) });