Skip to content
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

feat(core): rename private and public methods and properties #349

Merged
merged 13 commits into from
Oct 29, 2020

Conversation

francoischalifour
Copy link
Member

The Autocomplete naming were temporary and getting confusing because multiple concepts were mixed up. We spent some time rethinking the naming used in Autocomplete with @Shipow and came up with alternatives that make more sense to us.

This PR introduces multiple breaking changes that we'll need to document in the changelog—but that's fine since we're still in alpha.

Summary

  • Internal suggestions are now called Collections
type Collection = { source, items }
  • Items in lifecycle were sometimes named "suggestion", sometimes "item". They're now always called "item".
  • Item variables were prefixed with "suggestion", they're now prefixed with "item". E.g, itemUrl.
  • Source method getInputValuegetItemInputValue for clarity
  • Source method getSuggestionsgetItems
  • Source method getSuggestionUrlgetItemUrl
  • Setter method setHighlightedIndex is renamed setSelectedItemId for clarity. "highlight" is a word that we use for highlighting and snippetting. This renaming removes this confusion.
  • defaultHighlightedIndexdefaultSelectedItemId
  • Highlighting utils manipulate "hits", not "items" because they Algolia-transformed items called hits.

Next

  • shouldDropdownShow will also get renamed

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 26, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 9922243:

Sandbox Source
@algolia/js-example Configuration

return hits;
},
templates: {
item({ item }) {
return `
<div class="item-icon">${searchIcon}</div>
<div>
${reverseHighlightItem({
item,
${reverseHighlightHit({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do we win by calling this a hit, while we talk about item in the other spots? Is it because it's called getAlgoliaHits? Could that maybe be called getAlgoliaItems or search to remove the word hits?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An item is a generic object manipulated by Autocomplete. A hit is an item transformed by Algolia which contains _highlightResult, etc. A hit is a search term and it reflects the Algolia brand.

Comment on lines 6 to 7
getItemInputValue: ({ item }) => item.label,
getItemUrl: () => undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a good one, was inconsistent for sure!

setQuery,
setSuggestions,
setCollections,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collection is a list of items internally, while it's still called getSuggestions outside (or do I misread it?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, collections remain internal, except if you use the setters. getSuggestions is renamed to getItems, and the result of getItems is the items objet in a collection.

type Collection = { source, items };

Comment on lines +39 to +42
itemInputValue: ReturnType<
InternalAutocompleteSource<TItem>['getItemInputValue']
>;
itemUrl: ReturnType<InternalAutocompleteSource<TItem>['getItemUrl']>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these prefixed by item, when we're already in an item? could inputValue & url be sufficient?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're coming from getItemInputValue and getItemUrl so it's easier to map the naming to these.

const sections = state.suggestions.map((suggestion) => {
const items = suggestion.items;
const source = suggestion.source as InternalAutocompleteSource<TItem>;
const sections = state.collections.map((collection) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if getSources should be renamed to getCollections too (or is that not the same?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're not the same, as explained in #349 (comment).

setStatus('idle');
setSuggestions(suggestions as any);
setCollections(collections);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👍

const accumulatedSuggestionsCount = state.suggestions
.map((suggestion) => suggestion.items.length)
.reduce<number[]>((acc, suggestionCount, index) => {
const accumulatedCollectionssCount = state.collections
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accumulatedCollectionssCount -> two ss, intended or a typo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch—perhaps that announces a new broken key on my keyboard 🤪

See e162b51.

Copy link
Contributor

@eunjae-lee eunjae-lee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the changes.

@francoischalifour francoischalifour merged commit aeebe6d into next Oct 29, 2020
@francoischalifour francoischalifour deleted the refactor/naming branch October 29, 2020 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants