Giter Site home page Giter Site logo

Comments (6)

derrabauke avatar derrabauke commented on May 12, 2024 1

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.

cto-leaps avatar cto-leaps commented on May 12, 2024

@derrabauke Thank you for the tip, I was going bunkers!

from vuex-orm-localforage.

cto-leaps avatar cto-leaps commented on May 12, 2024

@eldomagan Any plan for Typescript support in the future?

from vuex-orm-localforage.

eldomagan avatar eldomagan commented on May 12, 2024

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.

derrabauke avatar derrabauke commented on May 12, 2024

@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.

Colorfulstan avatar Colorfulstan commented on May 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.