feathers-pinia

Connect your Feathers API to the elegant data store for Vue

Stars
52
Committers
19

Bot releases are hidden (Show)

feathers-pinia - 🎁 New `useFind` API

Published by marshallswain about 2 years ago

  • The old useFind has been renamed to useFindWatched.
  • A new useFind is now available with built-in pagination and fall-through cacheing.

New useFind API 🎁

The useFind API has been completely rewritten from scratch. A couple of its best features include

  • Intelligent Fall-Through Caching - Like SWR, but way smarter.
  • Pagination Support - Built in, sharing the same logic with usePagination.

Client Paging, Manual Fetch

Let's look at the two most-common use cases. This example shows client-side pagination with manual fetch:

import usePosts from '../stores/posts'

const postStore = usePosts()

const { data, next, prev, find } = postStore.useFind({ query: {} })

// fetch data
await find()

// move to the next page
await next()

// move to the previous page
await prev()

Server Paging, Auto Fetch

Another common use case is server-side pagination. Enable it by passing paginateOnServer in the params. You can also pull out isPending to show a status indicator when a request is pending. That's it!

import usePosts from '../stores/posts'

const postStore = usePosts()

const { data, next, prev, isPending } = postStore.useFind({ 
  query: {}, 
  paginateOnServer: true 
})

// move to the next page
await next()

// move to the previous page
await prev()

useFindWatched API ⚠️

To make migration to the new useFind API easier, the old useFind API has been renamed and is now called useFindWatched.

feathers-pinia - 🎁 SQL operators now natively supported.

Published by marshallswain about 2 years ago

🎉🎉🎉 As of [email protected], we now have support for SQL operators 🎉🎉🎉

This means you can use the following query operators like native operators. No configuration is necessary!

  • $like
  • $ilike
  • $iLike
  • $notLike
  • $notILike

Read more details, here: https://v1.feathers-pinia.pages.dev/guide/whats-new.html#support-sql-like-operators-%F0%9F%8E%81

Or try it out by running npm i feathers-pinia@pre.

feathers-pinia - 🎉 Bundle Size Optimizations

Published by marshallswain about 2 years ago

The overall bundle size has been reduced from around 20kb to 12kb, gzipped. This was done through

  • Replacing hefty dependencies, like lodash.debounce, with smaller equivalents, like just-debounce.
  • Optimizing the Vite build to externalize modules.

All of the modules highlighted, below, were able to be removed from the package, resulting in a much leaner build.

reduced-bundle-size

feathers-pinia - 🎁 New APIs for Automatic Associations, Lots of Little Things, Some Breaking

Published by marshallswain about 2 years ago

🎉 Use Default Values on the Class Definition

[Small breaking change] Defaults for values can now be specified directly on the Model interface, as shown below. Custom constructors have been made much cleaner due to the new instance.init() BaseModel method. After calling super(data, options) to initialize the BaseModel, the init method can be called from this:

// Minimum required constructor
constructor(data: Partial<Message> = {}, options: Record<string, any> = {}) {
  super(data, options)
  this.init(data)
}

Here are the technical details of how the new Model behavior works. For the TLDR version, just make your Model classes look like the example, below.

  • BaseModel no longer calls setupInstance, internally. If you use a custom constructor together with instanceDefaults and setupInstance, the two methods are run twice, wasting cycles.
  • BaseModel still calls instanceDefaults internally, which means it runs twice. If you are using instanceDefaults only for default values, as documented, then the performance impact will be negligible, even when ingesting large amounts of data from the API server. No complex logic should run in instanceDefaults. It has two purposes. Any use outside of these two purposes should be refactored into setupInstance:
    • Allow specifying default values with low boilerplate.
    • Allow conditional defaults values to be assigned based on incoming data.
  • Calling new User(data) without a custom BaseModel results in Model interface defaults always overwriting data.
  • Having a custom constructor allows Model instance default values to initialize as one would expect: not overwriting any other values.
  • Calling this.init(data) runs the instanceDefaults again and also runs setupInstance.
// Define the interface and defaults directly on the Model instead of `instanceDefaults`.
export class Message extends BaseModel {
  _id: number
  text = ''
  userId: null | number = null
  createdAt: Date | null = null

  // This is the minimum required constructor
  constructor(data: Partial<Message> = {}, options: Record<string, any> = {}) {
    super(data, options)
    this.init(data)
  }

  static setupInstance(message: Partial<Message>) {
    // access `store` and `models` from this
    const { store, models } = this
  }
}

🎁 New associateFind and associateGet Utilities

TODO: Finish docs then update this section.

feathers-pinia - 🐜 Improved Vue 2 compatibility

Published by marshallswain about 2 years ago

Several imports were still coming from 'vue' instead of vue-demi. The update makes no difference for Vue 3 apps, but apps using Vue 2 will be able to use the new features from the previous pre-release.

feathers-pinia - 🪲 Set TypeScript `types` to `dist/`

Published by marshallswain about 2 years ago

Now that we auto-generate the types, this release uses the generated types from dist/ rather than src/.

feathers-pinia - 🪲 Restore TypeScript `types` in `package.json`

Published by marshallswain about 2 years ago

This patch release puts the types property back in the package.json. They are set to src/.

feathers-pinia - 🦟 Fix Vite Build, Output TS Types

Published by marshallswain about 2 years ago

This bug addresses an issue where Vite's library mode's file output extension changed from feathers-pinia.es.js to feathers-pinia.mjs. The package.json has been updated to address the issue.

The build also now exports TypeScript types adjacent to the bundled files. The original TypeScript-based src is also published to npm.

feathers-pinia - 🐛 Fix bug with `useGet` error behavior

Published by marshallswain about 2 years ago

The returned error from useGet now resets properly on its own when a record is found.

feathers-pinia - 🐛 Bug fixed: plain js model instances now receive `id` after calling `.create()`

Published by marshallswain about 2 years ago

When you call instance.create() on a model instance that hasn't been added to the store, the instance will now update with the latest data from the server. This same behavior does not apply to .patch or .update. For those methods you'll need to call .addToStore() to make the item reactive.

feathers-pinia - 🪲 Bug Fixes for `instance.__isTemp` and `clone.save()`

Published by marshallswain about 2 years ago

Bugs Fixed

  • Fixes a bug where instance.__isTemp was the opposite of what it should have been. Includes test.
  • Fixes a bug where clone.save() would not return a clone. Includes tests Closes #52 Thanks to @emmanuelgeoffray for reporting this bug! 🎉
  • Fixes a bug where a clone would lose its prototype (associated with its Model class) after running through a save_handler in useClones.
  • Fixes a bug where in-memory, related data would be lost after an API call.

TypeScript Class Properties

Adds documentation for working with strictPropertyInitialization in tsconfig.json, so we don't have to put ! after every property in a class.

Other Changes

  • Updates prettier's printWidth to 120 to prevent unnecessary formatting.
feathers-pinia - 🎉 New Docs with Dark Mode! `handleClones` renamed to `useClones`

Published by marshallswain about 2 years ago

New Documentation

The documentation has been updated to use the latest and greatest Vitepress pre-release. The updated design is lovely, more mobile friendly and includes dark mode!

See the before/after screenshots at the bottom of these release notes.

handleClones is now useClones

The handleClones utility has been renamed to useClones. We now have more consistent naming between the utilities:

  • useFind
  • useGet
  • usePagination
  • useClones

useClones Docs

There is now a handle-clones placeholder page for old links to still work. The new docs page for useClones is found here.

To make this a non-breaking change, the handleClones export still works in this release. It is deprecated and will be removed in version 1.0.

New Docs Screenshots

New Home Page:
Screen Shot 2022-08-30 at 10 33 43 AM

Old Home Page:
Screen Shot 2022-08-30 at 10 33 09 AM

feathers-pinia - Additional context in useFind's queryWhen

Published by marshallswain over 2 years ago

The following computed properties have been added to the useFind context:

  • isPending
  • haveBeenRequested
  • haveLoaded
  • error

They are the same as the internal useFind state.

feathers-pinia - Fix props reactivity with handle-clones

Published by marshallswain over 3 years ago

Just what the label says. uses a computed internally to make sure the props are reactive.

feathers-pinia - 🐜 Fix handle-clones and Restore build

Published by marshallswain over 3 years ago

handle-clones

Sometimes the passed-in data was an instance but had lost its reactivity for whatever reason. This updates the handle-clones saveHandlers to always compare the clone against the original item in the store. Without this change, it was impossible to set an item back to its original value, since the item passed in the props was non-reactive and always retained its original value instead of updating as it should.

Restore Build

The build runs through typescript again because it produces more readable output, even if the sourcemaps seem to be off when running with Vite.

feathers-pinia - Use Vite to build rather than just compiling with TypeScript.

Published by marshallswain over 3 years ago

Testing the dev experience with a vite build

feathers-pinia - 🐜 `addToStore` is alias of `addOrUpdate`

Published by marshallswain over 3 years ago

A new action has been added to the service stores. addToStore does the same thing as add. but the name is more consistent with other methods that modify the store.

feathers-pinia - 🎁 Model class is available on each store as store.Model

Published by marshallswain over 3 years ago

You can now get access to the underlying Model class by referencing the Model getter on each service store.

feathers-pinia - Update packages

Published by marshallswain over 3 years ago