@tdreyno/pretty-please
Advanced tools
Comparing version 1.0.0-beta.12 to 1.0.0-beta.13
@@ -29,2 +29,3 @@ 'use strict'; | ||
// tslint:disable: max-classes-per-file | ||
const none = void 0; | ||
/** | ||
@@ -116,2 +117,3 @@ * Create a new task. | ||
Task.trySequence = trySequence; | ||
Task.none = none; | ||
/** | ||
@@ -118,0 +120,0 @@ * A special form of Task which can be resolved/rejected externally. |
// tslint:disable: max-classes-per-file | ||
import { range } from "../util"; | ||
export const none = void 0; | ||
/** | ||
@@ -72,2 +73,3 @@ * Create a new task. | ||
Task.trySequence = trySequence; | ||
Task.none = none; | ||
/** | ||
@@ -74,0 +76,0 @@ * A special form of Task which can be resolved/rejected externally. |
export declare type Reject<E> = (error: E) => void; | ||
export declare type Resolve<S> = (result: S) => void; | ||
export declare type Fork<E, S> = (reject: Reject<E>, resolve: Resolve<S>) => void; | ||
export declare const none: undefined; | ||
/** | ||
@@ -24,2 +25,3 @@ * Create a new task. | ||
static trySequence: typeof trySequence; | ||
static none: undefined; | ||
fork: Fork<E, S>; | ||
@@ -26,0 +28,0 @@ constructor(computation: Fork<E, S>); |
@@ -23,2 +23,3 @@ import axios from 'axios'; | ||
// tslint:disable: max-classes-per-file | ||
const none = void 0; | ||
/** | ||
@@ -93,2 +94,3 @@ * Create a new task. | ||
Task.trySequence = trySequence; | ||
Task.none = none; | ||
/** | ||
@@ -95,0 +97,0 @@ * A special form of Task which can be resolved/rejected externally. |
@@ -1,1 +0,1 @@ | ||
import axios from"axios";Object.prototype.andThen=function(fn){return fn(this)};function range(end,start=0){return Array(end-start).fill(undefined).map((_,i)=>start+i)}function to(fn){return(sum,_item,index,all)=>{const isLast=index===all.length-1;if(!isLast){return sum}return fn(all)}}class Task{constructor(computation){this.fork=computation}andThen(fn){return andThen(fn,this)}succeedIf(fn){return succeedIf(fn,this)}onlyOnce(){return onlyOnce(this)}toPromise(){return toPromise(this)}swap(){return swap(this)}map(fn){return map(fn,this)}tap(fn){return tap(fn,this)}mapError(fn){return mapError(fn,this)}mapBoth(handleError,handleSuccess){return mapBoth(handleError,handleSuccess,this)}fold(handleError,handleSuccess){return fold(handleError,handleSuccess,this)}orElse(fn){return orElse(fn,this)}ap(task){return ap(this,task)}wait(ms){return wait(ms,this)}retryIn(ms){return retryIn(ms,this)}retryWithExponentialBackoff(ms,times){return retryWithExponentialBackoff(ms,times,this)}}Task.fail=fail;Task.succeed=succeed;Task.empty=empty;Task.failIn=failIn;Task.succeedIn=succeedIn;Task.of=succeed;Task.all=all;Task.sequence=sequence;Task.firstSuccess=firstSuccess;Task.never=never;Task.fromPromise=fromPromise;Task.race=race;Task.external=external;Task.emitter=emitter;Task.trySequence=trySequence;class ExternalTask extends Task{constructor(){super((reject,resolve)=>{switch(this.lastState){case"error":reject(this.alreadyError);case"success":resolve(this.alreadyResult);case"pending":this.computationReject=reject;this.computationResolve=resolve}});this.lastState="pending"}reject(error){this.alreadyError=error;this.lastState="error";if(this.computationReject){this.computationReject(error)}}resolve(result){this.alreadyResult=result;this.lastState="success";if(this.computationResolve){this.computationResolve(result)}}}function external(){return new ExternalTask}function emitter(fn){const task=external();return[task,(...args)=>{try{task.resolve(fn(...args))}catch(e){task.reject(e)}}]}function succeed(result){return new Task((_,resolve)=>resolve(result))}const of=succeed;function empty(){return of(void 0)}function succeedIn(ms,result){return new Task((_,resolve)=>setTimeout(()=>resolve(result),ms))}function fail(error){return new Task((reject,_)=>reject(error))}function failIn(ms,error){return new Task((reject,_)=>setTimeout(()=>reject(error),ms))}function never(){return new Task(()=>void 0)}function andThen(fn,task){return new Task((reject,resolve)=>task.fork(reject,b=>fn(b).fork(reject,resolve)))}function succeedIf(fn,task){return new Task((reject,resolve)=>{const result=fn();if(result){resolve(result);return}task.fork(reject,resolve)})}function onlyOnce(task){let state="initialized";let cachedResult;let cachedError;let callbackId=0;const callbacks={};function notify(reject,resolve){const id=callbackId++;callbacks[id]={reject:reject,resolve:resolve}}function triggerReject(error){state="failure";cachedError=error;Object.keys(callbacks).forEach(id=>{callbacks[id].reject(error);delete callbacks[id]})}function triggerResolve(result){state="success";cachedResult=result;Object.keys(callbacks).forEach(id=>{callbacks[id].resolve(result);delete callbacks[id]})}return new Task((reject,resolve)=>{switch(state){case"success":resolve(cachedResult);break;case"failure":reject(cachedError);break;case"pending":notify(reject,resolve);break;case"initialized":state="pending";notify(reject,resolve);task.fork(triggerReject,triggerResolve)}})}function fromPromise(maybePromise){if(maybePromise instanceof Promise){return new Task((reject,resolve)=>maybePromise.then(resolve,reject))}return of(maybePromise)}function toPromise(task){return new Promise((resolve,reject)=>task.fork(reject,resolve))}function race(tasks){return new Task((reject,resolve)=>{let done=false;return tasks.map(task=>task.fork(error=>{if(done){return}done=true;reject(error)},result=>{if(done){return}done=true;resolve(result)}))})}class EndOfSequence extends Error{constructor(){super("End of sequence")}}function trySequence(onError,tasks){const[head,...tail]=tasks;if(!head){return fail(new EndOfSequence)}return head.orElse(e=>{const shouldContinue=onError(e);if(shouldContinue===false){return fail(e)}if(shouldContinue===true){return trySequence(onError,tail)}return shouldContinue})}function firstSuccess(tasks){return new Task((reject,resolve)=>{let isDone=false;let runningTasks=tasks.length;const errors=[];return tasks.map(task=>task.fork(error=>{if(isDone){return}runningTasks-=1;errors.push(error);if(runningTasks===0){reject(errors)}},result=>{if(isDone){return}isDone=true;resolve(result)}))})}function all(tasks){return new Task((reject,resolve)=>{let isDone=false;let runningTasks=tasks.length;const results=[];return tasks.map((task,i)=>task.fork(error=>{if(isDone){return}isDone=true;reject(error)},result=>{if(isDone){return}runningTasks-=1;results[i]=result;if(runningTasks===0){resolve(results)}}))})}function sequence(tasks){return tasks.reduce((sum,task)=>{return andThen(list=>{return map(result=>[...list,result],task)},sum)},succeed([]))}function swap(task){return new Task((reject,resolve)=>task.fork(resolve,reject))}function map(fn,task){return new Task((reject,resolve)=>task.fork(reject,result=>resolve(fn(result))))}function tap(fn,task){return map(result=>{fn(result);return result},task)}function mapError(fn,task){return new Task((reject,resolve)=>task.fork(error=>reject(fn(error)),resolve))}function mapBoth(handleError,handleSuccess,task){return mapError(handleError,map(handleSuccess,task))}function fold(handleError,handleSuccess,task){return new Task((_,resolve)=>task.fork(error=>resolve(handleError(error)),result=>resolve(handleSuccess(result))))}function orElse(fn,task){return new Task((reject,resolve)=>task.fork(error=>fn(error).fork(reject,resolve),resolve))}function ap(task,appliedTask){return new Task((reject,resolve)=>{let targetResult;let applierFunction;let hasResultLoaded=false;let isRejected=false;const handleResolve=onResolve=>{return x=>{if(isRejected){return}onResolve(x);if(applierFunction&&hasResultLoaded){resolve(applierFunction(targetResult))}}};const handleReject=x=>{if(isRejected){return}isRejected=true;reject(x)};task.fork(handleReject,handleResolve(x=>{applierFunction=x}));appliedTask.fork(handleReject,handleResolve(x=>{hasResultLoaded=true;targetResult=x}))})}function wait(ms,task){return new Task((reject,resolve)=>{setTimeout(()=>task.fork(reject,resolve),ms)})}function retryIn(ms,task){return task.orElse(()=>task.wait(ms))}function retryWithExponentialBackoff(ms,times,task){return range(times).reduce((sum,i)=>sum.retryIn(ms*2**i),task)}function get(url,config){return fromPromise(axios.get(url,config))}function delete_(url,config){return fromPromise(axios.delete(url,config))}function head(url,config){return fromPromise(axios.head(url,config))}function post(url,data,config){return fromPromise(axios.post(url,data,config))}function put(url,data,config){return fromPromise(axios.put(url,data,config))}function patch(url,data,config){return fromPromise(axios.patch(url,data,config))}function toJSON(resp){const type=resp.config?resp.config.responseType:"text";switch(type){case"json":return succeed(resp.data);case"text":try{return succeed(JSON.parse(resp.data))}catch(e){return fail(e)}default:return fail(new Error("Invalid data"))}}var HTTP=Object.freeze({__proto__:null,get:get,delete_:delete_,head:head,post:post,put:put,patch:patch,toJSON:toJSON});function initialize(){return{type:"Initialized"}}function pending(){return{type:"Pending"}}function succeed$1(result){return{type:"Success",result:result}}function fail$1(error){return{type:"Failure",error:error}}function fold$1(onInitialized,onPending,onFailure,onSuccess,remote){switch(remote.type){case"Initialized":return onInitialized();case"Pending":return onPending();case"Failure":return onFailure(remote.error);case"Success":return onSuccess(remote.result)}}function fromTask(task){return task.map(succeed$1).orElse(e=>of(fail$1(e)))}var RemoteData=Object.freeze({__proto__:null,initialize:initialize,pending:pending,succeed:succeed$1,fail:fail$1,fold:fold$1,fromTask:fromTask});export{EndOfSequence,HTTP,RemoteData,Task,range,to}; | ||
import axios from"axios";Object.prototype.andThen=function(fn){return fn(this)};function range(end,start=0){return Array(end-start).fill(undefined).map((_,i)=>start+i)}function to(fn){return(sum,_item,index,all)=>{const isLast=index===all.length-1;if(!isLast){return sum}return fn(all)}}const none=void 0;class Task{constructor(computation){this.fork=computation}andThen(fn){return andThen(fn,this)}succeedIf(fn){return succeedIf(fn,this)}onlyOnce(){return onlyOnce(this)}toPromise(){return toPromise(this)}swap(){return swap(this)}map(fn){return map(fn,this)}tap(fn){return tap(fn,this)}mapError(fn){return mapError(fn,this)}mapBoth(handleError,handleSuccess){return mapBoth(handleError,handleSuccess,this)}fold(handleError,handleSuccess){return fold(handleError,handleSuccess,this)}orElse(fn){return orElse(fn,this)}ap(task){return ap(this,task)}wait(ms){return wait(ms,this)}retryIn(ms){return retryIn(ms,this)}retryWithExponentialBackoff(ms,times){return retryWithExponentialBackoff(ms,times,this)}}Task.fail=fail;Task.succeed=succeed;Task.empty=empty;Task.failIn=failIn;Task.succeedIn=succeedIn;Task.of=succeed;Task.all=all;Task.sequence=sequence;Task.firstSuccess=firstSuccess;Task.never=never;Task.fromPromise=fromPromise;Task.race=race;Task.external=external;Task.emitter=emitter;Task.trySequence=trySequence;Task.none=none;class ExternalTask extends Task{constructor(){super((reject,resolve)=>{switch(this.lastState){case"error":reject(this.alreadyError);case"success":resolve(this.alreadyResult);case"pending":this.computationReject=reject;this.computationResolve=resolve}});this.lastState="pending"}reject(error){this.alreadyError=error;this.lastState="error";if(this.computationReject){this.computationReject(error)}}resolve(result){this.alreadyResult=result;this.lastState="success";if(this.computationResolve){this.computationResolve(result)}}}function external(){return new ExternalTask}function emitter(fn){const task=external();return[task,(...args)=>{try{task.resolve(fn(...args))}catch(e){task.reject(e)}}]}function succeed(result){return new Task((_,resolve)=>resolve(result))}const of=succeed;function empty(){return of(void 0)}function succeedIn(ms,result){return new Task((_,resolve)=>setTimeout(()=>resolve(result),ms))}function fail(error){return new Task((reject,_)=>reject(error))}function failIn(ms,error){return new Task((reject,_)=>setTimeout(()=>reject(error),ms))}function never(){return new Task(()=>void 0)}function andThen(fn,task){return new Task((reject,resolve)=>task.fork(reject,b=>fn(b).fork(reject,resolve)))}function succeedIf(fn,task){return new Task((reject,resolve)=>{const result=fn();if(result){resolve(result);return}task.fork(reject,resolve)})}function onlyOnce(task){let state="initialized";let cachedResult;let cachedError;let callbackId=0;const callbacks={};function notify(reject,resolve){const id=callbackId++;callbacks[id]={reject:reject,resolve:resolve}}function triggerReject(error){state="failure";cachedError=error;Object.keys(callbacks).forEach(id=>{callbacks[id].reject(error);delete callbacks[id]})}function triggerResolve(result){state="success";cachedResult=result;Object.keys(callbacks).forEach(id=>{callbacks[id].resolve(result);delete callbacks[id]})}return new Task((reject,resolve)=>{switch(state){case"success":resolve(cachedResult);break;case"failure":reject(cachedError);break;case"pending":notify(reject,resolve);break;case"initialized":state="pending";notify(reject,resolve);task.fork(triggerReject,triggerResolve)}})}function fromPromise(maybePromise){if(maybePromise instanceof Promise){return new Task((reject,resolve)=>maybePromise.then(resolve,reject))}return of(maybePromise)}function toPromise(task){return new Promise((resolve,reject)=>task.fork(reject,resolve))}function race(tasks){return new Task((reject,resolve)=>{let done=false;return tasks.map(task=>task.fork(error=>{if(done){return}done=true;reject(error)},result=>{if(done){return}done=true;resolve(result)}))})}class EndOfSequence extends Error{constructor(){super("End of sequence")}}function trySequence(onError,tasks){const[head,...tail]=tasks;if(!head){return fail(new EndOfSequence)}return head.orElse(e=>{const shouldContinue=onError(e);if(shouldContinue===false){return fail(e)}if(shouldContinue===true){return trySequence(onError,tail)}return shouldContinue})}function firstSuccess(tasks){return new Task((reject,resolve)=>{let isDone=false;let runningTasks=tasks.length;const errors=[];return tasks.map(task=>task.fork(error=>{if(isDone){return}runningTasks-=1;errors.push(error);if(runningTasks===0){reject(errors)}},result=>{if(isDone){return}isDone=true;resolve(result)}))})}function all(tasks){return new Task((reject,resolve)=>{let isDone=false;let runningTasks=tasks.length;const results=[];return tasks.map((task,i)=>task.fork(error=>{if(isDone){return}isDone=true;reject(error)},result=>{if(isDone){return}runningTasks-=1;results[i]=result;if(runningTasks===0){resolve(results)}}))})}function sequence(tasks){return tasks.reduce((sum,task)=>{return andThen(list=>{return map(result=>[...list,result],task)},sum)},succeed([]))}function swap(task){return new Task((reject,resolve)=>task.fork(resolve,reject))}function map(fn,task){return new Task((reject,resolve)=>task.fork(reject,result=>resolve(fn(result))))}function tap(fn,task){return map(result=>{fn(result);return result},task)}function mapError(fn,task){return new Task((reject,resolve)=>task.fork(error=>reject(fn(error)),resolve))}function mapBoth(handleError,handleSuccess,task){return mapError(handleError,map(handleSuccess,task))}function fold(handleError,handleSuccess,task){return new Task((_,resolve)=>task.fork(error=>resolve(handleError(error)),result=>resolve(handleSuccess(result))))}function orElse(fn,task){return new Task((reject,resolve)=>task.fork(error=>fn(error).fork(reject,resolve),resolve))}function ap(task,appliedTask){return new Task((reject,resolve)=>{let targetResult;let applierFunction;let hasResultLoaded=false;let isRejected=false;const handleResolve=onResolve=>{return x=>{if(isRejected){return}onResolve(x);if(applierFunction&&hasResultLoaded){resolve(applierFunction(targetResult))}}};const handleReject=x=>{if(isRejected){return}isRejected=true;reject(x)};task.fork(handleReject,handleResolve(x=>{applierFunction=x}));appliedTask.fork(handleReject,handleResolve(x=>{hasResultLoaded=true;targetResult=x}))})}function wait(ms,task){return new Task((reject,resolve)=>{setTimeout(()=>task.fork(reject,resolve),ms)})}function retryIn(ms,task){return task.orElse(()=>task.wait(ms))}function retryWithExponentialBackoff(ms,times,task){return range(times).reduce((sum,i)=>sum.retryIn(ms*2**i),task)}function get(url,config){return fromPromise(axios.get(url,config))}function delete_(url,config){return fromPromise(axios.delete(url,config))}function head(url,config){return fromPromise(axios.head(url,config))}function post(url,data,config){return fromPromise(axios.post(url,data,config))}function put(url,data,config){return fromPromise(axios.put(url,data,config))}function patch(url,data,config){return fromPromise(axios.patch(url,data,config))}function toJSON(resp){const type=resp.config?resp.config.responseType:"text";switch(type){case"json":return succeed(resp.data);case"text":try{return succeed(JSON.parse(resp.data))}catch(e){return fail(e)}default:return fail(new Error("Invalid data"))}}var HTTP=Object.freeze({__proto__:null,get:get,delete_:delete_,head:head,post:post,put:put,patch:patch,toJSON:toJSON});function initialize(){return{type:"Initialized"}}function pending(){return{type:"Pending"}}function succeed$1(result){return{type:"Success",result:result}}function fail$1(error){return{type:"Failure",error:error}}function fold$1(onInitialized,onPending,onFailure,onSuccess,remote){switch(remote.type){case"Initialized":return onInitialized();case"Pending":return onPending();case"Failure":return onFailure(remote.error);case"Success":return onSuccess(remote.result)}}function fromTask(task){return task.map(succeed$1).orElse(e=>of(fail$1(e)))}var RemoteData=Object.freeze({__proto__:null,initialize:initialize,pending:pending,succeed:succeed$1,fail:fail$1,fold:fold$1,fromTask:fromTask});export{EndOfSequence,HTTP,RemoteData,Task,range,to}; |
{ | ||
"name": "@tdreyno/pretty-please", | ||
"version": "1.0.0-beta.12", | ||
"version": "1.0.0-beta.13", | ||
"files": [ | ||
@@ -21,3 +21,3 @@ "dist-*/", | ||
"@pika/plugin-ts-standard-pkg": "^0.7.1", | ||
"@types/jest": "^24.0.19", | ||
"@types/jest": "^24.0.20", | ||
"@types/ramda": "^0.26.33", | ||
@@ -24,0 +24,0 @@ "@types/react": "^16.9.11", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
286768
3367
512