Nevertheless Published Mine

    objy

    0.6.985 • Public • Published

    OBJY - JavaScript objects with behaviour

    Node.js Package MIT License Gitter

    An object-driven programming framework, that uses behaviour-driven objects for building use cases.

    OBJY LOGO

    Installing

    OBJY can be used in Node and the Browser.

    Node

    npm install objy

    Browser

    <script src="https://cdn.jsdelivr.net/npm/objy/dist/browser.js">

    Programming with OBJY

    Programming on OBJY is done in two simple steps:

    1. Define an object family (a bucket of objects)
    2. Build and handle objects and tell them what to do.

    Quick example

    //Define Object Family
    OBJY.define({
       name: "object", // singular constructor name
       pluralName: "objects" // plural constructor name
    })
    
    OBJY.object({
       expired: false,
       expiration_date: {
          date: "12/31/2022",
          action: () => {
             obj.setProperty('expired', true).update();
          }
       },
       maintenance: {
          interval: "1PY",
          action: () => {
             console.log('annually maintenence');
          }
       }
    })

    Handling objects

    Objects are handled using an OBJY wrapper: OBJY.object().

    // Create an object (onCreate handlers will trigger)
    var myObj = OBJY.object({
       name: "Hello"
    });
    
    // Update an object (onChange handlers will trigger)
    myObj.name = "Hello World";
    
    // or use the built-in methods:
    myObj.addProperty('color', 'blue');
    
    // Delete an object (onDelete handlers will trigger)
    myObj.remove();

    Date or interval-based events:

    Events can either have a date or an interval. OBJY takes care of running the associated action.

    OBJY.object({
       ...
       expiration_date: {
          date: "12/31/2022",
          action: () => {
             obj.setProperty('expired', true).update();
          }
       },
       maintenance: {
          interval: "1PY",
          action: () => {
             console.log('annually maintenence');
          }
       }
    })

    Triggers

    Use onCreate, onChange or onDelete to capture these events and OBJY runs a custom action.

    OBJY.object({
       ...
       onDelete: {
          quit: {
             action: () => {
                console.log('Im now gone...')
             }}
       }
    })

    Custom actions

    OBJY.object({
       ...
       _id: 123,
       openMe: {
          type: "action",
          value: () => {x
             console.log('i am now open')
          }
       }
    })
    // call it like this
    OBJY.object({...}).getProperty('openMe').call()

    Inheritance

    // first object
    OBJY.object({
       _id: 123,
       type: "yogurt"
    })
    // second object that inherits from first object
    // inherit from one or more other objects using their id
    OBJY.object({
       ... 
       inherits: [123], 
       // type: "yogurt" and all other props are present here
    })

    Querying your objects

    Every object you create lives inside the OBJY instance. For accessing and working with all your objects, OBJY offers the following built-in query API:

    // Query all active objects
    OBJY.objects({json query}).get(objects => {
       console.log(objects) // an array containing the matched objects
    })

    Persistence

    OBJY objects either live in your JS instance or can come from other sources, like databases, file systems, or third-party systems. These sources are be defined when defining custom object wrappers.

    Important: When using persistence, the built-in CRUD operations .add(), .get(), .update() and .delete() must be used to commit changes to the persistence.

    // Define you own object wrapper with a storage mapper
    OBJY.define({
       name: "item",
       pluralName: "items",
       storage: new mongoDB(...)
    })
    
    // Add an object to persistence:
    OBJY.item({}).add(obj => {})
    
    // Query objects
    OBJY.items({query}).get(objy => {})
    
    // Update an object
    OBJY.item({...})
       .setProperty('name', 'test')
       .update(objy => {})
    
    // Delete an object
    OBJY.item({...}).delete(objy => {})

    Customization

    OBJY.define({
       ...
       // Attach your own storage (can be anything that supports crud)
       storage: OBJY.customStorage({
          add: () => {},
          getById: () => {},
          ...
       }),
       // Customize, how actions are executed
       processor: OBJY.customProcessor({
          execute: (action) => {}, 
          ...
       }),
       // Observe events yourself
       observer: OBJY.customObserver({
          run: () => {}
       })
    })

    Authors

    • Marco Boelling - Initial author - Twitter

    License

    This project is licensed under the MIT License - see the LICENSE.md file for details

    Connect

    • objy.io - OBJY's official website

      This feature is exclusive to Teams

      Illustration of wombats

      The package file explorer is only available for Teams at the moment.

      We may support exploring this package in the future. Check back soon.

      Install

      npm i objy

      Homepage

      objy.io

      DownloadsWeekly Downloads

      0

      Version

      0.6.985

      License

      MIT

      Unpacked Size

      801 kB

      Total Files

      39

      Last publish

      Collaborators

      • marcoboelling