UNPKG

redux-orm-angular

Version:

Helpers for integrating Angular and Redux ORM

3 lines (2 loc) 2.72 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("redux-orm")):"function"==typeof define&&define.amd?define(["exports","redux-orm"],t):t(e["redux-orm-angular"]={},e.ORM)}(this,function(e,t){"use strict";var n=[{name:"at",type:"evaluator"},{name:"count",type:"evaluator"},{name:"exclude",type:"clause"},{name:"exists",type:"evaluator"},{name:"filter",type:"clause"},{name:"first",type:"evaluator"},{name:"last",type:"evaluator"},{name:"orderBy",type:"clause"},{name:"toModelArray",type:"evaluator"},{name:"toRefArray",type:"evaluator"}];var r=function(){function e(e){if("function"==typeof e&&e.modelName)this.modelName=e.modelName;else{if("string"!=typeof e)throw new Error("A valid model name (string) or model (object) must be provided to selectData");this.modelName=e}}return e.prototype.all=function(){return e=this.getModelFromState.bind(this),t=[],r={fn:{name:"toModelArray",type:"evaluator"},args:null},o=function(n){var o=e(n).all();return t.forEach(function(e){var t=e.fn,n=e.args;o=o[t.name].apply(o,n)}),o[r.fn.name].apply(o,r.args)},n.forEach(function(e){o[e.name]=function(){if("clause"===e.type)return t.push({fn:e,args:arguments}),o;if("evaluator"===e.type)return r={fn:e,args:arguments},o;throw new Error('Unknown function type "'+e.type+'"')}}),o;var e,t,r,o},e.prototype.get=function(e){var t=this;return function(n){try{return t.getModelFromState(n).get(e)}catch(r){if("Model instance not found when calling get method"===r.message)return null;throw r}}},e.prototype.hasId=function(e){var t=this;return function(n){return t.getModelFromState(n).hasId(e)}},e.prototype.withId=function(e){var t=this;return function(n){try{return t.getModelFromState(n).withId(e)}catch(r){if(-1!==r.message.indexOf("instance with id "+e+" not found"))return null;throw r}}},e.prototype.getModelFromState=function(e){var n=t.ORM.angularConfig;if(!n)throw new Error("ORM.angularConfig should be set before using `selectData`");if(!n.instance)throw new Error("Impossible to find the ORM instance to use. Make sure you have configured ORM.angularConfig.instance to the ORM instance that you want to use with `selectData`");if(!n.stateKey)throw new Error("Impossible to find the state key from the config. Make sure you have configured ORM.angularConfig.stateKey to a non-empty value");if(!e[n.stateKey])throw new Error("Impossible to find the DB state; make sure you have configured ORM.angularConfig.stateKey and that you have a reducer running your ORM");return n.instance.session(e[n.stateKey])[this.modelName]},e}();e.ORMSelector=r,e.selectData=function(e){return new r(e)},Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=redux-orm-angular.umd.min.js.map