square / svelte-store

529 stars 35 forks source link

feat: tracked state now provides booleans instead of string #37

Closed Akolyte01 closed 2 years ago

Akolyte01 commented 2 years ago

feat: tracked state now provides booleans instead of string

until now tracked state stores held a string. This could be used in templates to check the state of the stores by comparing to a string. But that comparison had to be made every time and resulted in verbose checks when trying to see if the store was in one of several states (checking if loading or reloading, for example)

This PR changes it so instead those comparisons are made when the state is updated and provided as boolean properties of the store's value.

before:

{#if $myState === 'LOADING' || $myState === 'RELOADING'}
  //render something
{/if}

after:

{#if $myState.isPending}
  // render something
{/if}