Git Product home page Git Product logo

quick-prop's Introduction

QuickProp

If you are familiar with Vue.js component's prop, you already knows how to use QuickProp. QuickProp is a JavaScript data model made easy.

npm-version npm-download Jest CI Total alerts

Installation

npm i quick-prop

Usage

import QuickProp from 'quick-prop'
import { v4 as uuidv4 } from 'uuid';

class Todo extends QuickProp {
    constructor(todo = {}) {
        super({
            id: {
                type: [Number, String],
                default() {
                    return uuidv4()
                }
            },
            title: {
                type: String,
                required: true
            },
            completed: {
                type: Boolean,
                default: () => false
            }
        }, todo)
    }
}

const todo = new Todo({
    title: 'Example todo'
})

todo.completed = true

console.log(JSON.stringify(todo))

Result:

{
    "id": "f24b19a2-e327-4199-88e9-1c5c8e4b8b82",
    "title": "Example todo",
    "completed": true
}

Reactivity \w Vue

In some case where data reactivity is needed, you could use the Vuejs plugin to make quick-prop reactive.

import Vue from 'vue'
import { QuickPropVue } from 'quick-prop'

Vue.use(QuickPropVue)

Todo

  • Better implementation
  • Add Type Decorator
  • Vue Reactive

License

License under MIT

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.