Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixed result hydration in client
- Optimized result returning when no transformers are applied - Upgraded to v. 0.3.2
  • Loading branch information
mmoreram committed Sep 20, 2021
commit 563ffb06eb432914a1edc4b6c8237fd5606f939c
11 changes: 10 additions & 1 deletion dist/apisearch.js

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

2 changes: 1 addition & 1 deletion dist/apisearch.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/apisearch.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/apisearch.min.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion lib/Repository/HttpRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ var HttpRepository = /** @class */ (function (_super) {
* @return {Result}
*/
HttpRepository.prototype.applyTransformersToResult = function (result) {
if (!this.transformer.hasReadTransformers()) {
return result;
}
var subresults = result.getSubresults();
if (Object.keys(subresults).length > 0) {
Object.keys(subresults).map(function (key) {
Expand All @@ -495,7 +498,7 @@ var HttpRepository = /** @class */ (function (_super) {
}
return Result_1.Result.create(result.getQueryUUID(), result.getTotalItems(), result.getTotalHits(), result.getAggregations(), result.getSuggestions(), this
.transformer
.fromItems(result.getItems()));
.fromItems(result.getItems()), result.getAutocomplete());
};
/**
* @param response
Expand Down
4 changes: 4 additions & 0 deletions lib/Transformer/Transformer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export declare class Transformer {
* @param readTransformer
*/
addReadTransformer(readTransformer: ReadTransformer): void;
/**
* @return {boolean}
*/
hasReadTransformers(): boolean;
/**
* Add write transformer
*
Expand Down
6 changes: 6 additions & 0 deletions lib/Transformer/Transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ var Transformer = /** @class */ (function () {
.readTransformers
.push(readTransformer);
};
/**
* @return {boolean}
*/
Transformer.prototype.hasReadTransformers = function () {
return this.readTransformers.length > 0;
};
/**
* Add write transformer
*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apisearch",
"version": "0.3.1",
"version": "0.3.2",
"description": "Javascript client for Apisearch.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
6 changes: 6 additions & 0 deletions src/Repository/HttpRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,11 @@ export class HttpRepository extends Repository {
* @return {Result}
*/
private applyTransformersToResult(result: Result): Result {

if (!this.transformer.hasReadTransformers()) {
return result;
}

const subresults = result.getSubresults();

if (Object.keys(subresults).length > 0) {
Expand All @@ -488,6 +493,7 @@ export class HttpRepository extends Repository {
this
.transformer
.fromItems(result.getItems()),
result.getAutocomplete(),
);
}

Expand Down
7 changes: 7 additions & 0 deletions src/Transformer/Transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export class Transformer {
.push(readTransformer);
}

/**
* @return {boolean}
*/
public hasReadTransformers(): boolean {
return this.readTransformers.length > 0;
}

/**
* Add write transformer
*
Expand Down
4 changes: 4 additions & 0 deletions test/Result/Result.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ describe('Result/', () => {
);

let resultAsArray = result.toArray();
let resultObject = Result.createFromArray(resultAsArray);

it('Should work properly', () => {
expect(result.getAutocomplete()).to.be.equal('lolazo');
expect(resultAsArray.autocomplete).to.be.equal('lolazo');
expect(resultObject.getAutocomplete()).to.be.equal('lolazo');
});

let result2 = Result.create(
Expand All @@ -124,10 +126,12 @@ describe('Result/', () => {
);

let resultAsArray2 = result2.toArray();
let resultObject2 = Result.createFromArray(resultAsArray2);

it('Should work properly', () => {
expect(result2.getAutocomplete()).to.be.null;
expect(resultAsArray2.autocomplete).to.be.undefined;
expect(resultObject2.getAutocomplete()).to.be.null;
});
});

Expand Down