Skip to content

Commit

Permalink
Merge pull request #94 from basics/feature/optimization
Browse files Browse the repository at this point in the history
Feature/optimization
  • Loading branch information
StephanGerbeth authored Nov 26, 2024
2 parents 22b1a59 + eae508b commit 45c74c3
Show file tree
Hide file tree
Showing 36 changed files with 262 additions and 276 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions packages/observables/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Project Changelog

# [@rxjs-collection/observables-v1.0.6](https://github.com/basics/rxjs-collection/compare/@rxjs-collection/observables-v1.0.5...@rxjs-collection/observables-v1.0.6) (2024-11-25)


### Bug Fixes

* **operators:** restructured and added aliases ([1e53881](https://github.com/basics/rxjs-collection/commit/1e5388145a60f7cdb8c2ff1a980df204ad64b4f3))

# [@rxjs-collection/observables-v1.0.6-beta.1](https://github.com/basics/rxjs-collection/compare/@rxjs-collection/observables-v1.0.5...@rxjs-collection/observables-v1.0.6-beta.1) (2024-11-25)


Expand Down
Empty file removed packages/observables/index.js
Empty file.
4 changes: 2 additions & 2 deletions packages/observables/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rxjs-collection/observables",
"version": "1.0.6-beta.1",
"version": "1.0.6",
"description": "rxjs observables",
"license": "MIT",
"contributors": [
Expand All @@ -10,7 +10,7 @@
}
],
"type": "module",
"main": "index.js",
"main": "src/index.js",
"files": [
"./src/*"
],
Expand Down
1 change: 1 addition & 0 deletions packages/observables/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { connectionObservable } from './dom/window';
7 changes: 7 additions & 0 deletions packages/operators/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Project Changelog

# [@rxjs-collection/operators-v1.0.10](https://github.com/basics/rxjs-collection/compare/@rxjs-collection/operators-v1.0.9...@rxjs-collection/operators-v1.0.10) (2024-11-25)


### Bug Fixes

* **operators:** restructured and added aliases ([1e53881](https://github.com/basics/rxjs-collection/commit/1e5388145a60f7cdb8c2ff1a980df204ad64b4f3))

# [@rxjs-collection/operators-v1.0.10-beta.1](https://github.com/basics/rxjs-collection/compare/@rxjs-collection/operators-v1.0.9...@rxjs-collection/operators-v1.0.10-beta.1) (2024-11-25)


Expand Down
12 changes: 0 additions & 12 deletions packages/operators/fixtures/paginatedFetchFixture.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/operators/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rxjs-collection/operators",
"version": "1.0.10-beta.1",
"version": "1.0.10",
"description": "rxjs operators",
"license": "MIT",
"contributors": [
Expand All @@ -10,7 +10,7 @@
}
],
"type": "module",
"main": "index.js",
"main": "src/index.js",
"files": [
"./src/*"
],
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TestScheduler } from 'rxjs/testing';
import { beforeEach, describe, expect, test } from 'vitest';

import { cache } from './cache';
import { log } from './log';

describe('cache', () => {
let testScheduler;
Expand All @@ -22,7 +23,9 @@ describe('cache', () => {
testScheduler.run(({ cold, expectObservable }) => {
const stream = cold('a', { a: () => triggerVal.shift() }).pipe(
map(fn => fn()),
log('operators:cache:default:input'),
cache({ ttl: 2 })
// log('operators:cache:default:output')
);

const unsubA = '-^!';
Expand Down
2 changes: 1 addition & 1 deletion packages/operators/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export {
resolveBlob,
distinctUntilResponseChanged
} from './request/response';
export { retryWhenError } from './request/retry';
export { retryWhenRequestError } from './retry';
35 changes: 0 additions & 35 deletions packages/operators/src/json.js

This file was deleted.

10 changes: 0 additions & 10 deletions packages/operators/src/json/replacer.js

This file was deleted.

26 changes: 0 additions & 26 deletions packages/operators/src/json/reviver.js

This file was deleted.

30 changes: 0 additions & 30 deletions packages/operators/src/json/reworker/default.js

This file was deleted.

43 changes: 0 additions & 43 deletions packages/operators/src/json/reworker/token.js

This file was deleted.

72 changes: 48 additions & 24 deletions packages/operators/src/log.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
import { bgGreen } from 'ansi-colors';
import debug from 'debug';
import { connectable, finalize, Observable, Subject } from 'rxjs';
import { connectable, finalize, Observable, Subject, tap } from 'rxjs';

Check warning on line 3 in packages/operators/src/log.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

'Observable' is defined but never used

import { pipeWhen } from './when';

export const enableLog = tag => {
debug.enable(tag);
};

export const log = tag => {
var logger = debug(tag);
logger.log = console.log.bind(console);
logger.log = global.console.log.bind(console);
var error = debug(`${tag}:error`);

if (debug.enabled(tag)) {
return source => {
return new Observable(observer => {
return source.subscribe({
next: val => {
logger(val);
observer.next(val);
},
error: err => {
error(err);
observer.error(err);
},
complete: () => {
logger(bgGreen.bold('Complete!'));
observer.complete();
}
});
});
};
} else {
return source => source;
}
return source =>
source.pipe(
pipeWhen(
() => debug.enabled(tag),
tap({
subscribe: () => logger('subscribed'),
unsubscribe: () => logger('unsubscribed'),
finalize: () => logger('finalize'),
next: val => logger(val),
error: err => error(err),
complete: () => logger(bgGreen.bold('complete!'))
})
)
);
};

export const logResult = (tag, observable) => {
Expand All @@ -46,3 +40,33 @@ export const logResult = (tag, observable) => {
).connect();
});
};

// export const log = tag => {
// var logger = debug(tag);
// logger.log = global.console.log.bind(console);
// var error = debug(`${tag}:error`);

// if (debug.enabled(tag)) {
// return source =>
// new Observable(observer => {
// source.subscribe({
// subscribe: () => logger('subscribed'),
// unsubscribe: () => logger('unsubscribed'),
// finalize: () => logger('finalize'),
// next: val => {
// logger(val);
// observer.next(val);
// },
// error: err => {
// error(err);
// observer.error(err);
// },
// complete: () => {
// logger(bgGreen.bold('complete!'));
// observer.complete();
// }
// });
// });
// }
// return source => source;
// };
11 changes: 11 additions & 0 deletions packages/operators/src/log.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { describe, test } from 'vitest';

describe('log', () => {
test('default', () => {
//TODO: add test
});

test('logResult', () => {
//TODO: add test
});
});
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { concatMap, from, throwError } from 'rxjs';

import { cache } from './cache';
import { resolveBlob, resolveJSON, resolveText } from './response';
import { retryWhenError } from './retry';
import { retryWhenRequestError } from './retry';

export const request = ({ retry, cache: cacheOptions } = {}) => {
return source =>
Expand All @@ -14,7 +14,7 @@ export const request = ({ retry, cache: cacheOptions } = {}) => {
return throwError(() => new Error('Failed to fetch: resource not valid'));
}
}),
retryWhenError(retry),
retryWhenRequestError(retry),
cache(cacheOptions)
);
};
Expand Down
Loading

0 comments on commit 45c74c3

Please sign in to comment.