Comments (6)
For everybody in the same situation: Temporarily solved the TypeScript Error for now by manually dispatching the actions like this.Clip.dispatch("$create", {data...}
from vuex-orm-localforage.
@derrabauke Thank you for the tip, I was going bunkers!
from vuex-orm-localforage.
@eldomagan Any plan for Typescript support in the future?
from vuex-orm-localforage.
Hi all. Sorry for the late response. I'm very busy now with my daily job. I'm planning to make a full rewrite in typescript when I have little time. But contributions are welcome.
from vuex-orm-localforage.
@eldomagan No worries! A lot of plugins for the Vue ecosystem have to do a rewrite with Vue 3 and/or Typescript. When you start out with a base I will try to contribute.
from vuex-orm-localforage.
I use these shims to add TS support to my vuex-orm-localforage models:
methods got renamed to prevent confusion
import '@vuex-orm/core'
import Collection from '@vuex-orm/core/lib/data/Collection'
import InstanceOf from '@vuex-orm/core/lib/data/InstanceOf'
import * as Payloads from '@vuex-orm/core/lib/modules/payloads/Actions'
// https://github.com/eldomagan/vuex-orm-localforage
declare module '@vuex-orm/core' {
import { Condition } from '@vuex-orm/core/lib/modules/payloads/Actions'
class Model {
/** Load data from the IndexedDB store associated to a model and persist
* them in the Vuex Store using insertOrUpdate
* returns insertOrUpdate result
* @deprecated NOTE: using this method will replace data in vuex with
* data from indexedDB! This means if changes are not persisted, they
* will be replaced. Also this creates a lot of inserts, as all items
* are replaced one by one (log spam).
* If feasible, use $get(id) to update specific items or making sure
* they are fetched from indexedDB when needed.
* */
static $fetchPersisted<T extends typeof Model>(
this: T,
): Promise<Collection<InstanceOf<T>>>
/** Load data by id from the IndexedDB store associated and persist it
* to Vuex Store using insertOrUpdate
* returns insertOrUpdate result */
static $getPersisted<T extends typeof Model>(
this: T,
params: { id: number | string } | string,
): Promise<{ [key: string]: InstanceOf<T>[] }>
/** Like VuexORM insertOrUpdate, but also persist data to IndexedDB
* returns array with created data!? (see localforage setItem)*/
static $createPersisted<T extends typeof Model>(
this: T,
payload: Payloads.InsertOrUpdate,
): Promise<T[]>
/** Update records using VuexORM update (if "where" is set) or
* insertOrUpdate then persist changes to IndexedDB
* returns array with updated data!? (see localforage setItem)
* @deprecated it seems that $create is the better alternative here.
* with $update there is a bug when using it on the instance sometimes
* (error like "$self is null/undefined"), and create
* does the thing expected from update (insertOrUpdate)
* This error even happens sometimes if called on the class
* */
static $updatePersisted<T extends Model = this>(
this: typeof T,
payloadLikeVuexOrm: Payloads.Update | Payloads.InsertOrUpdate,
): Promise<T[]>
/** Like VuexORM create, but also replace all data from IndexedDB
* returns array with updated data!? (see localforage setItem) */
static $replacePersisted<T extends typeof Model>(
this: T,
payloadLikeVuexOrm: Payloads.Create,
): Promise<T[]>
/** Like VuexORM delete, but also remove data from IndexedDB
* returns ??? model.$localStore.removeItem(key)[]*/
static $deletePersisted<M extends typeof Model>(
this: M,
id:
| string
| number
| /* compound key, NOT array of ids */ (number | string)[]
| Condition,
): Promise<InstanceOf<T> | InstanceOf<T>[]>
/** Like VuexORM deleteAll, but also delete all data from IndexedDB */
static $deleteAllPersisted<M extends typeof Model>(this: M): Promise<void>
/**
* Deletes the instance from indexedDB and vuex-orm
* @see Model.$deletePersisted**/
deletePersisted<M extends typeof Model>(this: M): Promise<void> // TODO: response typing
}
}
from vuex-orm-localforage.
Related Issues (15)
- Unclear documentation HOT 4
- $delete (or remapped $deleteFromLocal) cause "Uncaught (in promise) TypeError: Cannot read property '$id' of null" HOT 1
- [Dependencies] How to remove lodash-es from final build HOT 2
- [Storybook] Issue when storybook hot reloaded HOT 4
- Custom options cannot applying HOT 2
- Cannot convert undefined or null to object HOT 1
- Extra Methods return indexed data array with missing model context
- fetch from api then save to indexdb? HOT 3
- Uncaught TypeError using $update
- How to configure LocalForage?
- sharing with the plugin plugin-axios
- how to include vuex-orm-localforage into vuex-orm-examples? HOT 4
- congrats
- vuex-orm-localforage breaks with @vuex-orm/core 0.34.1 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vuex-orm-localforage.