👑 Good Things Come to Those Who Wait: What’s new in Akita v2

Netanel Basal
Datorama Engineering
3 min readJan 31, 2019

--

Akita updates are coming in fast and furious — the last one was a little over a month ago, and now we’ve reached a new milestone — we’ve launched Akita 2.0. It’s another step in our plan to help you manage your states more efficiently and with less of a hassle.

We wanted to let you know that the main reason we bumped the version to 2.0.0 is that we’ve updated Typescript to the latest version. We’re using the conditional types feature, so if you’re working with Typescript 2.8 and above you should be good to go.

Let’s have a look at what’s new:

đź’Ş Multiple Active Support

As you may know, Akita’s Entity Store supports having an active attribute, which holds the active entity’s id. This can prove to be very useful in cases where you want to interact with the entity that is currently active.

In this release, we added support for maintaining a list of active entities instead of one. Let’s see how it works:

The only actions we need to do, is extend the MultiActiveState interface and initialize the active property to an array. With this setup, we’ll get the following functionality:

Here is a live example for caching the selected entities when navigates to a different page:

🙌 New Selectors

We’ve added two selectors to Akita’s Entity Query, which simplify the process of selecting the first and last entity in a collection. For example:

In addition to that, the selectMany selector now supports projection function:

👉 Miscellaneous

  • We’ve deprecated the getSnapshot() query method in favor of getValue().
  • The filterNil operator is strongly typed now, which means that the next operator in the chain will not be typed as null or undefined.

✍️ What’s Next

In the next release, we’ll add asynchronous support to the persistState plugin. This feature has already been submitted as a pull request, but we want to test it further. This will give you the option to save a store’s value to a persistent storage, such as indexDB, websql, or any other asynchronous API.

Akita with localForage

Akita continues to grow with more than 150k downloads so far. We’re getting a lot of great feedback, and we’re always open to new suggestions and improvements. You’re welcome to join Akita’s Gitter channel to address any questions you may have.

I’d like to thank Inbal Sinai and the rest of the contributors, who help make Akita better.

--

--

A FrontEnd Tech Lead, blogger, and open source maintainer. The founder of ngneat, husband and father.