Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #403 from algolia/feat/expose-userdata
Browse files Browse the repository at this point in the history
feat(store): expose userData through a new getter
  • Loading branch information
rayrutjes authored Mar 9, 2018
2 parents d94c73e + 1d943d4 commit 3f32a31
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/__tests__/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,27 @@ describe('Store', () => {
expect(store.page).toEqual(2);
});

test('can retrieve userData if it exists', () => {
const store = createStore();
store._helper = {
lastResults: {
userData: ['a value'],
},
};

expect(store.userData).toEqual(['a value']);
});

test('returns undefined as userData if no last response is available', () => {
const store = createStore();
expect(store.userData).toEqual(undefined);
});

test('returns undefined if not userData is part of the last response', () => {
const store = createStore();
expect(store.userData).toEqual(undefined);
});

test('should add "vue-instantsearch" User Agent to the client with the current version', () => {
const addAlgoliaAgent = jest.fn();
const client = {
Expand Down
8 changes: 8 additions & 0 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ export class Store {
return this._helper.lastResults.nbPages;
}

get userData() {
if (!this._helper.lastResults) {
return undefined;
}

return this._helper.lastResults.userData;
}

get totalResults() {
if (!this._helper.lastResults) {
return 0;
Expand Down

0 comments on commit 3f32a31

Please sign in to comment.