Code Monkey home page Code Monkey logo

mongoose-plugins-recurrency's Introduction

mongoose-plugins-recurrency

Build Status Coverage Status npm version Dependency Status devDependency Status peerDependency Status

This package was created so some mongoose plugins could be installed only once per schema. And not every time a new model is created using that same schema.

The option passed is if the plugin should be applied recursively(mongoose normal behavior), or just once for that schema.

Installation

npm install mongoose-plugins-recurrency

@NOTE: It requires mongoose as peerDependency.

Usage

var mongoose = require('mongoose');

// It automatically adds logic to mongoose.
require('mongoose-plugins-recurrency');

// Register Global plugin with recursive flag set to false to prevent it to be called more than once.
mongoose.plugin(function pluginA (schema, options){
    console.log('Registering only once');
}, {
    recursive: false
});

// Register Global plugin with recursive flag set to true to use mongoose normal behavior.
// @NOTE: recursive default value is true
mongoose.plugin(function pluginB(schema, options){
    console.log('Registering only once');
}, {
    recursive: true
});

var Dummy = new mongoose.Schema({
    title: String
});

// You also can also use it directly on a schema before building the models.
Dummy.plugin(function pluginC (schema, options){
    console.log('## Something Great ##');
}, {
    recursive: true // or false
});

var DummyA = mongoose.model('DummyA', Dummy);
var DummyB = mongoose.model('DummyB', Dummy);

// Right now Dummy schema should have 1 instance of pluginA, 2 instances of pluginB and 1 instance of pluginC

Tests

npm test

Credits

mongoose-plugins-recurrency's People

Watchers

 avatar  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.