Giter Club home page Giter Club logo

feathers-vuex's Introduction

feathers-vuex

Build Status Dependency Status Download Status

feathers-vuex service logo

Integrate the Feathers Client into Vuex

feathers-vuex is a first class integration of the Feathers Client and Vuex. It implements many Redux best practices under the hood, eliminates a lot of boilerplate code, and still allows you to easily customize the Vuex store.


NOTICE: this module is almost (but not quite) fully compatible with Feathers V4. The authentication module is written for Feathers V3. If you're going to use Feathers V4, please search the GitHub issues for "feathers crow authentication" for workarounds you can implement until this module is properly updated.

IN THE MEANTIME, it is highly recommended that you use the pre-release version, which is production ready for Feathers V4. A proper migration guide and updated documentation are currently in progress.


Features

  • Fully powered by Vuex & Feathers
  • Realtime By Default
  • Actions With Reactive Data
  • Local Queries
  • Fall-Through Caching
  • Feathers Query Syntax
  • $FeathersVuex Vue Plugin
  • Live Queries
  • Per-Service Data Modeling
  • Clone & Commit
  • Vuex Strict Mode
  • Per-Record Defaults
  • Data Level Computes
  • Relation Support

Demo & Documentation

Demo

See https://feathers-vuex.feathers-plus.com/index.html for full documentation.

Installation

npm install feathers-vuex --save

Basic Examples

To setup feathers-vuex, we first need to setup a Feathers Client. Here's an example using the latest @feathersjs npm packages.

feathers-client.js:

import feathers from '@feathersjs/feathers'
import socketio from '@feathersjs/socketio-client'
import auth from '@feathersjs/authentication-client'
import io from 'socket.io-client'

const socket = io('http://localhost:3030', {transports: ['websocket']})

const feathersClient = feathers()
  .configure(socketio(socket))
  .configure(auth({ storage: window.localStorage }))

export default feathersClient

And here's how you would integrate the Feathers Client into the Vuex store:

store/index.js:

import Vue from 'vue'
import Vuex from 'vuex'
import feathersVuex from 'feathers-vuex'
import feathersClient from '../feathers-client'

const { service, auth, FeathersVuex } = feathersVuex(feathersClient, { idField: '_id' })

Vue.use(Vuex)
Vue.use(FeathersVuex)

export default new Vuex.Store({
  plugins: [
    service('todos'),

    // Specify custom options per service
    service('/v1/tasks', {
      idField: '_id', // The field in each record that will contain the id
      nameStyle: 'path', // Use the full service path as the Vuex module name, instead of just the last section
      namespace: 'custom-namespace', // Customize the Vuex module name.  Overrides nameStyle.
      autoRemove: true, // Automatically remove records missing from responses (only use with feathers-rest)
      enableEvents: false, // Turn off socket event listeners. It's true by default
      addOnUpsert: true, // Add new records pushed by 'updated/patched' socketio events into store, instead of discarding them. It's false by default
      skipRequestIfExists: true, // For get action, if the record already exists in store, skip the remote request. It's false by default
      modelName: 'OldTask' // Default modelName would have been 'Task'
    })

    // Add custom state, getters, mutations, or actions, if needed.  See example in another section, below.
    service('things', {
      state: {},
      getters: {},
      mutations: {},
      actions: {}
    })

    // Setup a service with defaults for Model instances
    service('manufacturers', {
      instanceDefaults: {
        name: ''
      }
    })
    // Setup a service with light-weight relational data
    service('models', {
      instanceDefaults: {
        name: '',
        manufacturerId: '',
        manufacturer: 'Manufacturer' // Refers to data (populated on the server) that gets put in the `manufacturers` vuex store.
      }
    })

    // Setup the auth plugin.
    auth({ userService: 'users' })
  ]
})

Contributing

feathers-vuex tests run using StealJS, which is a 100% browser-based bundler.

Once you’ve installed all of the npm packages, start an http-server in the root folder:

cd feathers-vuex

npm i -g http-server

http-server

Then open the resulting page in your browser and navigate to the test folder to run the tests.

License

Copyright (c) Forever and Ever, or at least the current year.

Licensed under the MIT license.

feathers-vuex's People

Contributors

beeplin avatar bravo-kernel avatar calvinwalzel avatar cl3mm avatar cmeissl avatar cronik avatar daffl avatar elbarkey avatar fratzinger avatar imrec avatar joeinnes avatar jskrzypek avatar louim avatar marshallswain avatar marsimeau avatar mattchewone avatar metareason avatar mgesmundo avatar ndamjan avatar nickbolles avatar nriesco avatar pedrolvr avatar plasticrake avatar ricochet1k avatar sebastianoe avatar supermomme avatar thilina-dulanjana avatar tmcmah1 avatar ucokfm avatar wdmtech avatar

Watchers

 avatar

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.