better tests
This commit is contained in:
parent
eb2d3e1b25
commit
4d2ed1260d
23
dist/smartrx.classes.observableintake.d.ts
vendored
23
dist/smartrx.classes.observableintake.d.ts
vendored
@ -7,9 +7,32 @@ export declare class ObservableIntake<T> {
|
|||||||
completed: Promise<void>;
|
completed: Promise<void>;
|
||||||
private completedDeffered;
|
private completedDeffered;
|
||||||
private observableFunctions;
|
private observableFunctions;
|
||||||
|
private generator;
|
||||||
|
private buffered;
|
||||||
|
private payloadBuffer;
|
||||||
constructor();
|
constructor();
|
||||||
setObservable(observableFunc: any): void;
|
setObservable(observableFunc: any): void;
|
||||||
push(payloadArg: T): void;
|
push(payloadArg: T): void;
|
||||||
|
/**
|
||||||
|
* pushes many payloads as array
|
||||||
|
* @param payloadArgArray
|
||||||
|
*/
|
||||||
|
pushMany(payloadArgArray: T[]): void;
|
||||||
|
/**
|
||||||
|
* sets a generator to query the next pushed value
|
||||||
|
* @param generatorArg
|
||||||
|
*/
|
||||||
|
setGenerator(generatorArg: any): void;
|
||||||
|
makeBuffered(): void;
|
||||||
subscribe(...args: any[]): Subscription;
|
subscribe(...args: any[]): Subscription;
|
||||||
|
/**
|
||||||
|
* request the next values in the quantity specified
|
||||||
|
* @param howManyArg if a generator is set, of a buffer exists, this allows retrieving values
|
||||||
|
*/
|
||||||
|
request(howManyArg: number): void;
|
||||||
|
/**
|
||||||
|
* signals the completion of this observable
|
||||||
|
*/
|
||||||
signalComplete(): void;
|
signalComplete(): void;
|
||||||
|
private internalPush(payloadArg);
|
||||||
}
|
}
|
||||||
|
57
dist/smartrx.classes.observableintake.js
vendored
57
dist/smartrx.classes.observableintake.js
vendored
@ -15,6 +15,9 @@ class ObservableIntake {
|
|||||||
// nothing
|
// nothing
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
this.generator = null;
|
||||||
|
this.buffered = false;
|
||||||
|
this.payloadBuffer = [];
|
||||||
this.observable = rxjs_1.Observable.create((observerArg) => {
|
this.observable = rxjs_1.Observable.create((observerArg) => {
|
||||||
this.observableFunctions.next = (...args) => {
|
this.observableFunctions.next = (...args) => {
|
||||||
return observerArg.next(...args);
|
return observerArg.next(...args);
|
||||||
@ -31,14 +34,64 @@ class ObservableIntake {
|
|||||||
this.observable = observableFunc();
|
this.observable = observableFunc();
|
||||||
}
|
}
|
||||||
push(payloadArg) {
|
push(payloadArg) {
|
||||||
this.observableFunctions.next(payloadArg);
|
if (this.buffered) {
|
||||||
|
this.payloadBuffer.push(payloadArg);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.internalPush(payloadArg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* pushes many payloads as array
|
||||||
|
* @param payloadArgArray
|
||||||
|
*/
|
||||||
|
pushMany(payloadArgArray) {
|
||||||
|
for (let item of payloadArgArray) {
|
||||||
|
this.push(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* sets a generator to query the next pushed value
|
||||||
|
* @param generatorArg
|
||||||
|
*/
|
||||||
|
setGenerator(generatorArg) {
|
||||||
|
this.generator = generatorArg;
|
||||||
|
}
|
||||||
|
makeBuffered() {
|
||||||
|
this.buffered = true;
|
||||||
}
|
}
|
||||||
subscribe(...args) {
|
subscribe(...args) {
|
||||||
return this.observable.subscribe(...args);
|
return this.observable.subscribe(...args);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* request the next values in the quantity specified
|
||||||
|
* @param howManyArg if a generator is set, of a buffer exists, this allows retrieving values
|
||||||
|
*/
|
||||||
|
request(howManyArg) {
|
||||||
|
if (howManyArg === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (let i = 0; i !== howManyArg; i++) {
|
||||||
|
if (this.payloadBuffer.length > 0) {
|
||||||
|
this.internalPush(this.payloadBuffer.shift());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const nextPayload = this.generator();
|
||||||
|
this.internalPush(nextPayload);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* signals the completion of this observable
|
||||||
|
*/
|
||||||
signalComplete() {
|
signalComplete() {
|
||||||
this.observableFunctions.complete();
|
this.observableFunctions.complete();
|
||||||
}
|
}
|
||||||
|
internalPush(payloadArg) {
|
||||||
|
this.observableFunctions.next(payloadArg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.ObservableIntake = ObservableIntake;
|
exports.ObservableIntake = ObservableIntake;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRyeC5jbGFzc2VzLm9ic2VydmFibGVpbnRha2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHJ4LmNsYXNzZXMub2JzZXJ2YWJsZWludGFrZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDZDQUE0QztBQUM1QywrQkFBK0M7QUFHL0M7O0dBRUc7QUFDSDtJQWFFO1FBVFEsd0JBQW1CLEdBQVE7WUFDakMsSUFBSSxFQUFFLENBQUMsVUFBVSxFQUFFLEVBQUU7Z0JBQ25CLFVBQVU7WUFDWixDQUFDO1lBQ0QsUUFBUSxFQUFFLENBQUMsVUFBVSxFQUFFLEVBQUU7Z0JBQ3ZCLFVBQVU7WUFDWixDQUFDO1NBQ0YsQ0FBQTtRQUdDLElBQUksQ0FBQyxVQUFVLEdBQUcsaUJBQVUsQ0FBQyxNQUFNLENBQUMsQ0FBQyxXQUFXLEVBQUUsRUFBRTtZQUNsRCxJQUFJLENBQUMsbUJBQW1CLENBQUMsSUFBSSxHQUFHLENBQUMsR0FBRyxJQUFJLEVBQUUsRUFBRTtnQkFDMUMsTUFBTSxDQUFDLFdBQVcsQ0FBQyxJQUFJLENBQUMsR0FBRyxJQUFJLENBQUMsQ0FBQTtZQUNsQyxDQUFDLENBQUE7WUFDRCxJQUFJLENBQUMsbUJBQW1CLENBQUMsUUFBUSxHQUFHLENBQUMsR0F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DQUFDO1lBQ3JCLE1BQU0sQ0FBQTtRQUNSLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNOLEdBQUcsQ0FBQyxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsRUFBRSxDQUFDLEtBQUssVUFBVSxFQUFFLENBQUMsRUFBRSxFQUFFLENBQUM7Z0JBQ3RDLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxhQUFhLENBQUMsTUFBTSxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUM7b0JBQ2xDLElBQUksQ0FBQyxZQUFZLENBQUMsSUFBSSxDQUFDLGFBQWEsQ0FBQyxLQUFLLEVBQUUsQ0FBQyxDQUFBO2dCQUMvQyxDQUFDO2dCQUFDLElBQUksQ0FBQyxDQUFDO29CQUNOLE1BQU0sV0FBVyxHQUFHLElBQUksQ0FBQyxTQUFTLEVBQUUsQ0FBQTtvQkFDcEMsSUFBSSxDQUFDLFlBQVksQ0FBQyxXQUFXLENBQUMsQ0FBQTtnQkFDaEMsQ0FBQztZQUNILENBQUM7UUFDSCxDQUFDO0lBQ0gsQ0FBQztJQUVEOztPQUVHO0lBQ0gsY0FBYztRQUNaLElBQUksQ0FBQyxtQkFBbUIsQ0FBQyxRQUFRLEVBQUUsQ0FBQTtJQUNyQyxDQUFDO0lBRU8sWUFBWSxDQUFFLFVBQVU7UUFDOUIsSUFBSSxDQUFDLG1CQUFtQixDQUFDLElBQUksQ0FBQyxVQUFVLENBQUMsQ0FBQTtJQUMzQyxDQUFDO0NBQ0Y7QUFqR0QsNENBaUdDIn0=
|
@ -7,15 +7,34 @@ tap.test('should create a valid instance of observableinstake', async () => {
|
|||||||
expect(testObservableIntake).to.be.instanceOf(smartrx.ObservableIntake)
|
expect(testObservableIntake).to.be.instanceOf(smartrx.ObservableIntake)
|
||||||
})
|
})
|
||||||
|
|
||||||
tap.test('expect testObserservableIntake to be lazy', async (tools) => {
|
tap.test('expect testObserservableIntake to push things', async (tools) => {
|
||||||
const testObserservableIntake = new smartrx.ObservableIntake()
|
const testObserservableIntake = new smartrx.ObservableIntake()
|
||||||
testObserservableIntake.subscribe(value => {
|
testObserservableIntake.subscribe(value => {
|
||||||
console.log(value)
|
console.log(value)
|
||||||
})
|
})
|
||||||
|
|
||||||
testObserservableIntake.push('hi')
|
testObserservableIntake.push('hi')
|
||||||
|
testObserservableIntake.push('wow')
|
||||||
testObserservableIntake.signalComplete()
|
testObserservableIntake.signalComplete()
|
||||||
await testObserservableIntake.completed
|
await testObserservableIntake.completed
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tap.test('expect testObserservableIntake to push things', async (tools) => {
|
||||||
|
const testObserservableIntake = new smartrx.ObservableIntake()
|
||||||
|
testObserservableIntake.push('hi')
|
||||||
|
testObserservableIntake.push('wow')
|
||||||
|
testObserservableIntake.makeBuffered()
|
||||||
|
testObserservableIntake.push('jo')
|
||||||
|
testObserservableIntake.subscribe(value => {
|
||||||
|
console.log(value)
|
||||||
|
testObserservableIntake.signalComplete()
|
||||||
|
})
|
||||||
|
testObserservableIntake.request(1)
|
||||||
|
await testObserservableIntake.completed
|
||||||
|
})
|
||||||
|
|
||||||
|
tap.test('', async () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
tap.start()
|
tap.start()
|
||||||
|
@ -17,6 +17,9 @@ export class ObservableIntake<T> {
|
|||||||
// nothing
|
// nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private generator = null
|
||||||
|
private buffered = false
|
||||||
|
private payloadBuffer = []
|
||||||
|
|
||||||
constructor () {
|
constructor () {
|
||||||
this.observable = Observable.create((observerArg) => {
|
this.observable = Observable.create((observerArg) => {
|
||||||
@ -37,14 +40,66 @@ export class ObservableIntake<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
push (payloadArg: T) {
|
push (payloadArg: T) {
|
||||||
this.observableFunctions.next(payloadArg)
|
if (this.buffered) {
|
||||||
|
this.payloadBuffer.push(payloadArg)
|
||||||
|
} else {
|
||||||
|
this.internalPush(payloadArg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pushes many payloads as array
|
||||||
|
* @param payloadArgArray
|
||||||
|
*/
|
||||||
|
pushMany (payloadArgArray: T[]) {
|
||||||
|
for (let item of payloadArgArray) {
|
||||||
|
this.push(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets a generator to query the next pushed value
|
||||||
|
* @param generatorArg
|
||||||
|
*/
|
||||||
|
setGenerator (generatorArg) {
|
||||||
|
this.generator = generatorArg
|
||||||
|
}
|
||||||
|
|
||||||
|
makeBuffered() {
|
||||||
|
this.buffered = true
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribe (...args) {
|
subscribe (...args) {
|
||||||
return this.observable.subscribe(...args)
|
return this.observable.subscribe(...args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* request the next values in the quantity specified
|
||||||
|
* @param howManyArg if a generator is set, of a buffer exists, this allows retrieving values
|
||||||
|
*/
|
||||||
|
request (howManyArg: number) {
|
||||||
|
if (howManyArg === 0) {
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i !== howManyArg; i++) {
|
||||||
|
if (this.payloadBuffer.length > 0) {
|
||||||
|
this.internalPush(this.payloadBuffer.shift())
|
||||||
|
} else {
|
||||||
|
const nextPayload = this.generator()
|
||||||
|
this.internalPush(nextPayload)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* signals the completion of this observable
|
||||||
|
*/
|
||||||
signalComplete () {
|
signalComplete () {
|
||||||
this.observableFunctions.complete()
|
this.observableFunctions.complete()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private internalPush (payloadArg) {
|
||||||
|
this.observableFunctions.next(payloadArg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user