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

json-vuex

v0.0.4-5

Published

Simple vuex - jsonapi connector.

Downloads

3

Readme

vuex-jsonapi

Simple vuex - jsonapi connector.

Specs:

  1. The library should be able to request any jsonapi server with several configuration files describing the models. The responses should be formatted for vuex latter using, as models define. The requests should be defined in the same way.

  2. The library offers two different APIs: jsonapi and vuex. Utilities to ease the use of jsonapi server implementation. And some vuex actions and getters for these entities.

  3. The library should accept configuration objects in this way:

/* ******** OPERATION MODULE **************/
const operationConf = {
  type: 'node--operation',
  attributes: {
    title: {
      type: 'string',
      required: true,
      isArray: false,
      name: 'title',
    }
    ,
  },
  relationships: {
    pledges: {
      type: 'node--pledge',
      required: false,
      isArray: true,
      name: 'pledges',
    },
  }
};

const moduleOperation = {
  baseUrl: 'url',
  name: 'pledges',
  entities: [operationConf],
};

/* *************** PLEDGE MODULE ***********/
const burdenConf = {
  type: 'node--burden',
  attributes: {
    title: {
      type: 'string',
      required: true,
      isArray: false,
      name: 'title',
    }
    ,
  },
  relationships: { }
};

const plegdeConf = {
  type: 'node--pledge',
  attributes: {
    title: {
      type: 'string',
      required: true,
      isArray: false,
      name: 'title',
    }
    ,
  },
  relationships: {
    burdens: {
      type: 'node--burden',
      required: false,
      isArray: true,
      name: 'burdens',
    },
  }
};

const modulePledge = {
  baseUrl: 'url',
  name: 'pledges',
  entities: [burdenConf, plegdeConf],
};

/* ****************** Register ******/
import { vuexAdapter, jsonapiAdapter } from 'vuex-jsonapi';
import store from './store';

// You can use this object to perform http requests against jsonapi server.
const operationJsonapiService = jsonapiAdapter.createService(moduleOperation);

// You can use this object to initialize a vuex module. If you pass in a jsonapiService
// then the module should perform http request when several actions are dispatched.
const operationVuexModule = vuexAdapter.createModule(moduleOperation, operationJsonapiService);

store.registerModule(operationVuexModule);

vuexAdapter API

The vuexModule created with vuexAdapter.createModule function should return a valid object to initialize a new vue store module.

For example, if you try with

  • const operationVuexModule = vuexAdapter.createModule(moduleOperation)

it should return:

{
    state: {
        operation: {
            ids: [],
            entities: {},
        },
    },
    mutations: {
        CLEAR_MODULE,
        UPSERT_ENTITY,
        REMOVE_ENTITY,
    },
    actions: {
        clearModuleAction,
        upsertOperationAction,
        removeOperationAction,
    },
    getters: {
        // TODO find where to place getById, find, etc.
    },
}

You can try something more complicated:

import { vuexAdapter, jsonapiAdapter } from 'vuex-jsonapi';

const pledgeService = jsonapiAdapter.createService(modulePledge);
const pledgeVuexModule = vuexAdapter.createModule(modulePledge, pledgeService);

pledgeVuexModule should return:

{
    state: {
        pledge: {
            ids: [],
            entities: {},
        },
        burden: {
            ids: [],
            entities: {},
        },
    },
    mutations: {
        CLEAR_MODULE,
        UPSERT_ENTITY,
        REMOVE_ENTITY,
    },
    actions: {
        clearModuleAction,
        upsertPledgeAction,
        removePledgeAction,
        upsertBurdenAction,
        removeBurdenAction,
    },
    getters: {
        // TODO find where to place getById, find, etc.
    },
}

In this case, when the library performs the upserts or removes actions, then library should use the jsonapiAdapter service to do the appropriate http requests.

jsonapiAdapter API

The jsonapiService created with jsonapiAdapter.createService function has the following structure:

{
 fetch(id) // fetch entity by id
 fetchAll() // fetch all entities
 create(payload) //create entity
 update(payload) // update entity
 upsert(payload) // update or create entity
 remove(id) //remove entity from colection    
}
  1. jsonapiService#fetch // TODO
  2. jsonapiService#fetchAll // TODO
  3. jsonapiService#create // TODO
  4. jsonapiService#update // TODO
  5. jsonapiService#remove // TODO

Future

  1. Prefetch related models.
  2. Mode cache.
  3. Enable Offline.
  4. Extensibility: Middlewares for processing and formatting. Middlewares for Authentications models. Create vuex modules with customs properties, mutations, actions and getters.

Authors

Alejandro Garrido / Alejandro Manjón Boream