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

v-crud-state

v1.1.4

Published

A Vue mixin that allows you simply to manage CRUD state.

Downloads

3

Readme

v-crud-state

A Vue mixin that allows you simply to manage CRUD state.

Installation

npm i v-crud-state --save

About state

This package recognizes 4 states from hash value of URL by default.

  • index
  • create
  • edit
  • show

It means that your URL should be https://example.com/test#index if you'd like to set state as index.

And state value is also available using :.

https://example.com/test#edit:15 https://example.com/test#show:value

Preparation

Set this.initState() in mounted().

new Vue({
    el: '#app',
    mounted:function() {

        this.initState();

    }
});

Usage

This package automatically calls onChangeState() when changing URL.
So add the method as follows.

new Vue({
    el: '#app',
    methods: {
        onChangeState: function(state, stateValue) {

            // Your code here

        }
    }
});

Note: state and stateValue are optional.

Retrieve current state

You can retrieve a current state through this.state.

if(this.state == 'create') {

    // create

}

Or you also have specific ways.

if(this.isIndex) {

    // Index

} else if(this.isCreate) {

    // Create

} else if(this.isEdit) {

    // Edit

} else if(this.isShow) {

    // Show

} else if(this.hasState) {

    // Has state

}

Retrieve state value

You can retrieve a current state value through this.stateValue.

const value = this.stateValue;

Note: Default value is null.

Default state

If a current state is not available, the state will change to the default one that you set in advance.

data: {
    defaultState: 'index' // optional
}

It means that a hash of the URL will automatically change to #index in this case.

Additional states

Your own states are available by setting additionalStates in data property.

data: {
    additionalStates: ['confirmation']
},

In this case, your URL should be https://example.com/test#confirmation.

Of course, you can retrieve state value as follows.
https://example.com/test#confirmation:value

Retrieve value corresponding a state

For example, you have titles object in data as follows.

data: {
    titles: {
        index: 'Title of INDEX',
        create: 'Title of CREATE',
        edit: 'Title of EDIT',
        show: 'Title of SHOW',
        confirmation: 'Title of confirmation' // In case that you set an additional state called "confirmation".
    }
}

In this case, you can automatically retrieve a title corresponding a current state through stateData().

const title = this.stateData('titles');    // depending on the states

License

This package is licensed under the MIT License.

Copyright 2018 Sukohi Kuhoh