UNPKG

@loona/angular

Version:

App State Management done with GraphQL (angular integration)

2 lines 7.22 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("rxjs"),require("apollo-angular"),require("rxjs/operators"),require("@loona/core"),require("apollo-cache")):"function"==typeof define&&define.amd?define("@loona/angular",["exports","@angular/core","rxjs","apollo-angular","rxjs/operators","@loona/core","apollo-cache"],e):e((t.loona=t.loona||{},t.loona.angular={}),t.ng.core,t.rxjs,t.apollo.core,t.rxjs.operators,t.loona.core,t.apollo.cache.core)}(this,function(t,o,a,n,i,c,e){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(t,e)};function u(t,e){function o(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}var s=function(){return(s=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var r in e=arguments[o])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function p(t,e){var o="function"==typeof Symbol&&t[Symbol.iterator];if(!o)return t;var n,r,i=o.call(t),a=[];try{for(;(void 0===e||0<e--)&&!(n=i.next()).done;)a.push(n.value)}catch(c){r={error:c}}finally{try{n&&!n.done&&(o=i["return"])&&o.call(i)}finally{if(r)throw r.error}}return a}function f(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(p(arguments[e]));return t}var l=new o.InjectionToken("Loona/State"),y=new o.InjectionToken("Loona/ChildState"),d=new o.InjectionToken("Loona/Cache"),h="@@init",v="@@effects/init",g="@@effects/update",b=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return u(e,t),e}(a.Observable),m=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return u(e,t),e.prototype.ngOnDestroy=function(){this.complete()},e.decorators=[{type:o.Injectable}],e}(a.Subject),j=function(e){function t(){return e.call(this,{type:h})||this}return u(t,e),t.prototype.next=function(t){if(void 0===t)throw new TypeError("Actions must be objects");if("undefined"==typeof t.type)throw new TypeError("Actions must have a type property");e.prototype.next.call(this,t)},t.prototype.complete=function(){},t.prototype.ngOnDestroy=function(){e.prototype.complete.call(this)},t.decorators=[{type:o.Injectable}],t.ctorParameters=function(){return[]},t}(a.BehaviorSubject),E=function(){function t(t,e,o,n,r){this.apollo=t,this.manager=e,this.actions=o,this.direct$=new a.Subject,this.queue$=a.merge(o,this.direct$).pipe(i.observeOn(a.queueScheduler)),this.queue$.subscribe({next:function(t){n.next(t)},error:function(t){r.handleError(t)}})}return t.prototype.query=function(t,e,o){return this.apollo.watchQuery(c.isDocument(t)?s({query:t,variables:e},o):t)},t.prototype.mutate=function(t,e,o){var n=this,r=c.isDocument(t)?s({mutation:t,variables:e},o):t;return this.apollo.mutate(c.withUpdates(r,this.manager)).pipe(i.tap(function(t){n.direct$.next(c.buildActionFromResult(r,t))}),i.catchError(function(t){return n.direct$.next(c.buildActionFromError(r,t)),a.throwError(t)}))},t.prototype.dispatch=function(t){if(c.isMutation(t)){var e=c.getMutation(t);this.mutate(s({mutation:e},t)).subscribe()}else this.actions.next(s({type:c.getActionType(t)},t))},t.prototype.extract=function(){return this.apollo.getClient().extract()},t.prototype.reset=function(){this.apollo.getClient().resetStore()},t.prototype.restore=function(t){this.apollo.getClient().restore(t)},t.decorators=[{type:o.Injectable}],t.ctorParameters=function(){return[{type:n.Apollo},{type:c.Manager},{type:j},{type:m},{type:o.ErrorHandler}]},t}(),A=function(){function t(t,e,o){this.effects={},this.getContext=function(){return s({},c.buildContext({cache:o,getCacheKey:c.buildGetCacheKey(o)},e.getClient()),{dispatch:t.dispatch.bind(t)})}}return t.prototype.addEffects=function(n,t){var r=this;if(t){var e=function(o){i.effects[o]||(i.effects[o]=[]),t[o].forEach(function(t){var e=t.propName;r.effects[o].push(n[e].bind(n))})},i=this;for(var o in t)e(o)}},t.prototype.runEffects=function(e){var o=this,t=e.type;c.isMutationAsAction(e)&&(t=c.getNameOfMutation(e.options.mutation));var n=this.effects[t];n&&n.forEach(function(t){t(e,o.getContext())})},t.decorators=[{type:o.Injectable}],t.ctorParameters=function(){return[{type:E},{type:n.Apollo},{type:e.ApolloCache,decorators:[{type:o.Inject,args:[d]}]}]},t}(),x=function(){function t(t,e){this.effects=t,this.scannedActions=e,this.actionsSubscription=null}return t.prototype.start=function(){var e=this;this.actionsSubscription||(this.actionsSubscription=this.scannedActions.subscribe(function(t){e.effects.runEffects(t)}))},t.prototype.ngOnDestroy=function(){this.actionsSubscription&&(this.actionsSubscription.unsubscribe(),this.actionsSubscription=null)},t.decorators=[{type:o.Injectable}],t.ctorParameters=function(){return[{type:A},{type:m}]},t}();function S(){var e=[];return{names:e,add:function(t){e.push(t.constructor&&t.constructor.name)}}}function I(t,e){return{instance:e.get(t),meta:t[c.METADATA_KEY]}}function M(i){return function(){for(var t,e=[],o=0;o<arguments.length;o++)e[o]=arguments[o];try{t=i.apply(void 0,f(e))}catch(n){return Promise.reject(n)}return t instanceof Promise||function r(t){return t instanceof a.Observable}(t)?a.from(t).toPromise():Promise.resolve(t)}}var C=function(){function t(t,e,o,r,n,i){var a=this;this.effects=t,n.start();var c=S(),u=c.names,s=c.add;e.forEach(function(t){var e=I(t,i),o=e.instance,n=e.meta;r.addState(o,n,M),a.addEffects(o,n.effects),s(o)}),o.dispatch({type:v,states:u})}return t.prototype.addEffects=function(t,e){this.effects.addEffects(t,e)},t.decorators=[{type:o.NgModule}],t.ctorParameters=function(){return[{type:A},{type:Array,decorators:[{type:o.Inject,args:[l]}]},{type:E},{type:c.Manager},{type:x},{type:o.Injector}]},t}(),O=function(){function t(t,r,i,e,a){var o=S(),n=o.names,c=o.add;t.forEach(function(t){var e=I(t,r),o=e.instance,n=e.meta;i.addState(o,n,M),a.addEffects(o,n.effects),c(o)}),e.dispatch({type:g,states:n})}return t.decorators=[{type:o.NgModule}],t.ctorParameters=function(){return[{type:Array,decorators:[{type:o.Inject,args:[y]}]},{type:o.Injector},{type:c.Manager},{type:E},{type:C}]},t}(),T=function(){function t(){}return t.forRoot=function(t){return void 0===t&&(t=[]),{ngModule:C,providers:f([E,j,m,{provide:b,useExisting:m}],t,[{provide:l,useValue:t},{provide:c.Manager,useFactory:_,deps:[d,o.Injector]},{provide:c.LoonaLink,useFactory:w,deps:[c.Manager]},A,x])}},t.forChild=function(t){return void 0===t&&(t=[]),{ngModule:O,providers:f(t,[{provide:y,useValue:t}])}},t.decorators=[{type:o.NgModule}],t}();function w(t){return new c.LoonaLink(t)}function _(t,e){return new c.Manager({cache:t,getClient:function(){return e.get(n.Apollo).getClient()}})}t.Manager=c.Manager,t.LoonaLink=c.LoonaLink,t.State=c.State,t.Mutation=c.Mutation,t.Update=c.Update,t.Resolve=c.Resolve,t.Effect=c.Effect,t.Actions=b,t.Loona=E,t.LoonaModule=T,t.INITIAL_STATE=l,t.CHILD_STATE=y,t.LOONA_CACHE=d,t.INIT=h,t.UPDATE_EFFECTS=g,t.ROOT_EFFECTS_INIT=v,t.ɵb=j,t.ɵa=m,t.ɵg=A,t.ɵh=x,t.ɵd=O,t.ɵc=C,t.ɵe=w,t.ɵf=_,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=loona.angular.umd.min.js.map