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

vue-entity-manager

v0.1.14

Published

For better data managment in vue/vuex store

Downloads

3

Readme

Vue-entity-manager

Vue-antity-manager is a tool to help you easily manage your states with vue / vuex. By providing structure and performance. It allows you to reduce the number of server requests with a caching system. It integrates perfectly with your existing architecture and tools you already use in your projects.

Usage

installation

npm i vue-entity-manager

or

yarn add vue-entity-manager

Initialisation

import entityStateManager from "vue-entity-manager";

const manager = entityStateManager("id");

id is the primary or unique key of each entity in your list. If you do not specify a value, id will be the default entry.

export default {
  namespaced: true,
  state: () => ({
    dataEntities: manager.initialState,
    current: {},
  ...

   getters: {
    selectAllPostsDataEntities(state) {
      return state.dataEntities;
    },
  ...

Entities

dataEntities contains the structure used by state-manager it is an arbitrary name. You can manage the structure manually or by using the following function manager.combienToDataEntities( state.dataEntities, entities);

  actions: {
    async fetchFakeAPI(vuexContext, {}) {
      try {
        fetch("https://jsonplaceholder.typicode.com/posts")
          .then((response) => response.json())
          .then((data) => {
            vuexContext.commit("setFakeAPIPosts", data);
          })
          ...
    },
...
 mutations: {
    setFakeAPIPosts(state, entities) {
      const posts = manager.setAllEntities(entities);
      state.dataEntities = { ...state.dataEntities, ...posts };
    },
  ...

OR

...
 mutations: {
    setFakeAPIPosts(state, entities) {
      const posts = manager.setAllEntities(entities);
      state.dataEntities = manager.combienToDataEntities(
        state.dataEntities,
        posts
      );
    },
  ...

Details

We are talking about details of all requests returned by id and which are not lists. The details have another entry in the dataEntities and are handled separately from the entities.

manager.hasDetails(state.dataEntities, id) allows you to check if the details with a specific id already exist in the store. The http request is no longer executed if the details id = 50 have already been called once.

...
  actions: {
    async fetchFakeAPIById({ commit, state }, {}) {

      const hasDetails = manager.hasDetails(state.dataEntities, 50);
      if (hasDetails === false) {
        try {
          fetch("https://jsonplaceholder.typicode.com/posts/50")
            .then((response) => response.json())
           ...

manager.upsertDetails is a curry function you can directly use it as follows manager.upsertDetails(details)(state.dataEntities) or as in the examples below.

...
 mutations: {
     setFakeAPIPostsDetails(state, details) {
      const posts = manager.upsertDetails(details);
      state.dataEntities = {
        ...state.dataEntities,
        ...posts(state.dataEntities),
      };
    },
  ...

OR

...
 mutations: {
    setFakeAPIPosts(state, entities) {
      const posts = manager.upsertDetails(details);
      state.dataEntities = manager.combienToDataEntities(
        state.dataEntities,
        posts(state.dataEntities))
      };
    },
  ...

compareAndFind

If you need to filter a list by another list.

...
 findPostByCommentsIds({ commit, state, rootState}) {
    const comments = manager.entitiesToArray(rootState.comments.dataEntities);
    const posts = manager.entitiesToArray(state.dataEntities);

    const _posts = compareAndFind(posts, comments)((posts, comment) => post.id === comment.postId)
    ...

compareAndMergeWith

If you need to combine 2 object lists with an entry key for the second list.

...
 postWithCommentss({ commit, state, rootState}) {
    const comments = manager.entitiesToArray(rootState.comments.dataEntities);
    const posts = manager.entitiesToArray(state.dataEntities);

    const postAndcomments = manager.compareAndMergeWith(
        posts,
        comments,
        "comments" //
      );
    ...

Manager Collection Functions

  • initialState : Creates the initial state in the designated entry. eg state.dataEntities.

  • setAllEntities: Structure the entities to be by the suiste added in the state.dataEntities.

  • upserEntity: Add/update an entity in the state.dataEntities.

  • deleteEntity: Delete an entity in the state.dataEntities.

  • upsertManyEntities: Add/update many entities in the state.dataEntities.

  • upsertDetails: Add/update datails in the state.dataEntities.

  • getEntityById: Takes an entity that already exists in the store

  • getDetailsById: Takes an details that already exists in the store

  • hasEntity: Check if the entity already exists in the store.

  • hasDetails: Check if the datails already exists in the store.

  • entitiesToArray: Transform entities into entity list without changing the default structure

  • detailsToArray: Transform entities into entity list without changing the default structure combienToDataEntities: Combine entities or details with state.dataEntities