New variant method API
#70
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related #34 #35
Motivation
variantprovides an API that allows us to render different components based on$storevalue, but$storevalue type is limited to string, and it's not convenient to use this API with different$storetypes.Imagine we have
$userstore andisAdminboolean property and we want to render different components based on this property. With the current API, we need to write something like that:We may notice that this is inconvenient and the code looks strange. To solve this problem, we need to extend
variantAPI so that developers can define the required component based on any type of $store value.New API usage example
When our
$storecontains a value with a type different from string, we can pass an array to cases property. Each case hasviewfield andfiltermethod that takes$storevalue and returns a boolean value.variantreturned view component will render that component that first matchfilterfrom up to down.Tasks:
Changelogs:
NonEmptyArraytype in types.ts