Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: function based initial config on the Helper #5724

Closed
bobylito opened this issue Aug 25, 2016 · 3 comments
Closed

API: function based initial config on the Helper #5724

bobylito opened this issue Aug 25, 2016 · 3 comments

Comments

@bobylito
Copy link
Contributor

One thing that we've noticed is that modifying a SearchParameter object is much simpler that working with the raw data structure. Also implementations based on the data structure is likely to break at some point if it ever evolves, whereas with the functions of the SearchParameters we can maintain the same API while modifying the underlying structure.

Proposal

var helper = algoliasearchHelper(client, index, function(params) {
  return params.addDisjunctiveFacet('categories')
           .addDisjunctiveFacetRefinement('categories', 'shirts');
});

This won't remove the possibility to pass an object, it's just a more friendly alternative to set the configuration and the default parameters.

@vvo
Copy link
Contributor

vvo commented Aug 25, 2016

I am trying to see if it provides a nicer API than what we have today.

With the new API:

var helper = algoliasearchHelper(client, index, function(params) {
  return params
    .addDisjunctiveFacet('categories')
    .addHierarchicalFacet('products', {separator: '<'})
    .addDisjunctiveFacetRefinement('categories', 'shirts');
});

VS the current API:

var helper = algoliasearchHelper(client, index, {
  facets: ['categories'],
  hierarchicalFacets: [{
    products: {separator: '<'}
  }]
});
helper.addDisjunctiveFacetRefinement('categories', 'shirts');

I feel what we could ask ourselves here is: "What does this API brings today that cannot be done easily with the current API?" and I am not sure to find a lot of differences.

Still for sure your example feels less complex to understand: only function calls and no need to iterate on the helper multiple times.

@bobylito
Copy link
Contributor Author

I feel what we could ask ourselves here is: "What does this API brings today that cannot be done easily with the current API?" and I am not sure to find a lot of differences.

You are right, for today, the benefits are thin. User wise it make only a slight difference.

However the programmatic API is more future proof (does not rely on structure that can change) and I would like to propose this alternative in order to deprecate the object one. Also proposing this would be also a win for instantsearch.js, for which this paradigm is closer.

Also providing a function means that it can be replay. Which could also be interesting for default parameters implementation.

@bobylito
Copy link
Contributor Author

bobylito commented Sep 8, 2017

If the state is provided from somewhere else (like the URL or any cold storage like the local-storage) we would still need to have a way to provide a plain JS Object. In the case of this proposal we can still instanciate a new SearchParameters with just the JS object but this makes the implementation less straightforward.

var coldState = getStateFromSomewhere();
var h = algoliasearchHelper(client, index, () => new SearchParameters(coldState));

@dhayab dhayab added the Library: AlgoliaSearch Helper Issues in algoliasearch-helper label Jul 11, 2023
@dhayab dhayab transferred this issue from algolia/algoliasearch-helper-js Jul 11, 2023
@algolia algolia locked and limited conversation to collaborators Jul 11, 2023
@dhayab dhayab converted this issue into discussion #5739 Jul 11, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

3 participants