Skip to content

Commit

Permalink
Merge pull request #214 from dhilt/issue-213-resolve-adapter-methods-…
Browse files Browse the repository at this point in the history
…immediately-if-scroller-is-not-initialized

Patch Adapter methods resolver
  • Loading branch information
dhilt authored Sep 26, 2020
2 parents 4bf4dbc + b4a833e commit 993a5ca
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package-dist.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-ui-scroll",
"version": "1.8.2",
"version": "1.8.3",
"description": "Infinite/virtual scroll for Angular",
"main": "./bundles/ngx-ui-scroll.umd.js",
"module": "./fesm5/ngx-ui-scroll.js",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"deploy-app": "npm run build-app && firebase deploy",
"preinstall": "cd server && npm install",
"postinstall": "npm run build-app",
"pack:install": "npm run build && npm pack ./dist && npm install ngx-ui-scroll-1.8.2.tgz --no-save",
"pack:install": "npm run build && npm pack ./dist && npm install ngx-ui-scroll-1.8.3.tgz --no-save",
"pack:start": "npm run pack:install && npm start",
"build": "node build.js",
"publish:lib": "npm run build && npm publish ./dist",
Expand Down
31 changes: 21 additions & 10 deletions src/component/classes/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,28 @@ export class Adapter implements IAdapter {
eof$: Subject<boolean>;
itemsCount: number;

private relax$: Subject<AdapterMethodRelax>;
private relax$: Subject<AdapterMethodRelax> | null;

private getPromisifiedMethod(method: Function) {
return (...args: any[]) =>
new Promise(resolve => {
this.relax$.pipe(
filter(value => !!value),
take(1)
).subscribe(value => resolve(value));
if (this.relax$) {
this.relax$.pipe(
filter(value => !!value),
take(1)
).subscribe(value => resolve(value));
}
method.apply(this, args);
if (!this.relax$) {
resolve();
}
});
}

constructor(publicContext: IAdapter | null, getWorkflow: WorkflowGetter, logger: Logger) {
this.getWorkflow = getWorkflow;
this.logger = logger;
this.relax$ = new Subject<AdapterMethodRelax>();
this.relax$ = null;

// restore original values from the publicContext if present
const adapterProps = publicContext
Expand Down Expand Up @@ -201,19 +206,23 @@ export class Adapter implements IAdapter {

// self-pending
if (onAdapterRun$) {
if (!this.relax$) {
this.relax$ = new Subject<AdapterMethodRelax>();
}
const relax$ = this.relax$;
onAdapterRun$.subscribe(({ status, payload }) => {
let isLoadingSub;
if (status === ProcessStatus.start) {
this.relax$.next(false);
relax$.next(false);
isLoadingSub = this.isLoading$
.pipe(filter(isLoading => !isLoading), take(1))
.subscribe(() => this.relax$.next({ success: true, immediate: false }));
.subscribe(() => relax$.next({ success: true, immediate: false }));
}
if (status === ProcessStatus.done || status === ProcessStatus.error) {
if (isLoadingSub) {
isLoadingSub.unsubscribe();
}
this.relax$.next({
relax$.next({
success: status !== ProcessStatus.error,
immediate: true,
...(status === ProcessStatus.error ? { error: payload ? payload.error : 'true' } : {})
Expand All @@ -224,7 +233,9 @@ export class Adapter implements IAdapter {
}

dispose() {
this.relax$.complete();
if (this.relax$) {
this.relax$.complete();
}
}

reset(options?: IDatasourceOptional): any {
Expand Down
1 change: 1 addition & 0 deletions src/component/processes/clip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default class Clip {
`, range: [${clipped[0]}..${clipped[clipped.length - 1]}]`
]);
logger.stat('after clip');
clip.reset();
}

}
2 changes: 1 addition & 1 deletion src/ui-scroll.version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default '1.8.2';
export default '1.8.3';
9 changes: 9 additions & 0 deletions tests/adapter.clip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,14 @@ describe('Adapter Clip Spec', () => {
})
);

makeTest({
config: { datasourceSettings: { adapter: true } },
title: `should resolve immediately before scroller initialization`,
it: (misc: Misc) => async (done: Function) => {
await misc.adapter.clip();
done();
}
});

});

0 comments on commit 993a5ca

Please sign in to comment.