-
Notifications
You must be signed in to change notification settings - Fork 332
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
Conversation
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:
|
return hits; | ||
}, | ||
templates: { | ||
item({ item }) { | ||
return ` | ||
<div class="item-icon">${searchIcon}</div> | ||
<div> | ||
${reverseHighlightItem({ | ||
item, | ||
${reverseHighlightHit({ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
getItemInputValue: ({ item }) => item.label, | ||
getItemUrl: () => undefined, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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 };
itemInputValue: ReturnType< | ||
InternalAutocompleteSource<TItem>['getItemInputValue'] | ||
>; | ||
itemUrl: ReturnType<InternalAutocompleteSource<TItem>['getItemUrl']>; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accumulatedCollectionssCount
-> two s
s, intended or a typo?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
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
itemUrl
.getInputValue
→getItemInputValue
for claritygetSuggestions
→getItems
getSuggestionUrl
→getItemUrl
setHighlightedIndex
is renamedsetSelectedItemId
for clarity. "highlight" is a word that we use for highlighting and snippetting. This renaming removes this confusion.defaultHighlightedIndex
→defaultSelectedItemId
Next
shouldDropdownShow
will also get renamed