npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vuex-orm-cordova

v0.1.0

Published

Vuex-ORM Plugin to sync the data against a Cordova SQLite DB using localforage.

Downloads

4

Readme

JavaScript Style Guide License

Vuex ORM Plugin: LocalForage

VuexORMCordova is a fork of VuexORMLocalForage that lets you sync your Vuex store with a Cordova SQLite database using LocalForage.

Installation

Install Cordova-sqlite-storage plugin

cordova plugin add cordova-sqlite-storage

Add the package to your dependencies

yarn add vuex-orm-cordova

Or

npm install --save vuex-orm-cordova

Then you can setup the plugin

import VuexORM from '@vuex-orm/core'
import VuexORMCordova from 'vuex-orm-cordova'

const database = new VuexORM.Database()

VuexORM.use(VuexORMCordova, {
  database
})

// ...

export default () => new Vuex.Store({
  namespaced: true,
  plugins: [VuexORM.install(database)]
})

See https://vuex-orm.github.io/vuex-orm/guide/prologue/getting-started.html#create-modules on how to setup the database

Actions

This plugin add some vuex actions to load and persist data in an IndexedDB

| Action | Description | | ------- | ----------- | | $fetch | Load data from the IndexedDB store associated to a model and persist them in the Vuex Store | | $get | Load data by id from the IndexedDB store associated and persist it to Vuex Store | | $create | Like VuexORM insertOrUpdate, but also persist data to IndexedDB | | $update | Update records using VuexORM update or insertOrUpdate then persist changes to IndexedDB | | $replace | Like VuexORM create, but also replace all data from IndexedDB | | $delete | Like VuexORM delete, but also remove data from IndexedDB | | $deleteAll | Like VuexORM deleteAll, but also delete all data from IndexedDB |

Example Usage

<template>
  <div>
    <input type="text" v-model="todo">
    <input type="button" @click="addTodo">

    <ul>
      <li v-for="todo in todos" :key="todo.id">{{ todo.title }}</li>
    </ul>
  </div>
</template>

<script>
  import Todo from './store/models/Todo'

  export default {
    data () {
      return {
        todo: ''
      }
    },

    computed: {
      todos () {
        return Todo.query().all()
      }
    },

    async mounted () {
      // Load todos from IndexedDB
      await Todo.$fetch()
    },

    methods: {
      addTodo () {
        if (this.todo) {
          // Insert the todo in VuexORM Store and also persist it to IndexedDB
          Todo.$create({
            title: this.todo
          })
        }
      }
    }
  }
</script>

Configuration Options

These are options you can pass when calling VuexORM.use()

{
  // The VuexORM Database instance
  database,

  /**
   * LocalForage config options
   *
   * @see https://github.com/localForage/localForage#configuration
   */
  localforage: {
    name: 'vuex', // Name is required
    ...
  },

  /**
   * You can override names of actions introduced by this plugin
   */
  actions: {
    $get: '$get',
    $fetch: '$fetch',
    $create: '$create',
    $update: '$update',
    $replace: '$replace',
    $delete: '$delete',
    $deleteAll: '$deleteAll'
  }
}

You can also override localforage config per model

class Post extends Model {
  static localforage = {
    driver: localforage.WEBSQL,
    storeName: 'my_posts'
  }
}

Using with other VuexORM Plugin

There may be a conflict when using this plugin along with other VuexORM plugins as they are following the same API (aka they introduced the same actions: $fetch, $create...)

Just override actions names like that

VuexORM.use(VuexORMLocalForage, {
  database,
  actions: {
    $get: '$getFromLocal',
    $fetch: '$fetchFromLocal',
    $create: '$createLocally',
    $update: '$updateLocally',
    $replace: '$replaceLocally',
    $delete: '$deleteFromLocal',
    $deleteAll: '$deleteAllFromLocal'
  }
})

Then

Post.$fetchFromLocal() // instead of Post.$fetch()
...