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

mozy

v0.5.2

Published

A model library using lazy initialization, factories and instance registries.

Downloads

11

Readme

mozy · GitHub license npm version Coverage Status

A model library using lazy initialization, factories and instance registries.

Installation

npm install mozy

Defining models

import mozy from 'mozy';

export class Rect extends mozy.Model {

  get x() {
    return this.get('x');
  }
  set x(value) {
    this.set('x', value);
  }

  /**
   * Skipping y, width, height ...
   */

  _getDefaults() {
    return Object.assign(super._getDefaults(), {
      identity: Rect.identity,
      x: 0.0,
      y: 0.0,
      width: 0.0,
      height: 0.0
    });
  }

}

Rect.identity = 'shape.Rect';

/**
 * Skipping EdgeSizes definition
 */

export class Dimensions extends mozy.Model {

  get contentBox() {
    return this._getModel('contentBox');
  }

  get padding() {
    return this._getModel('padding');
  }

  get borderWidth() {
    return this._getModel('borderWidth');
  }

  get margin() {
    return this._getModel('margin');
  }

  _getModel(property) {
    return mozy.modelRegistry.getModel(this.get(property));
  }

  _getDefaults() {
    return Object.assign(super._getDefaults(), {
      identity: Dimensions.identity,
      contentBox: {identity: Rect.identity},
      padding: {identity: EdgeSizes.identity},
      borderWidth: {identity: EdgeSizes.identity},
      margin: {identity: EdgeSizes.identity}
    });
  }

}

Dimensions.identity = 'layout.Dimensions';

/**
 * Register identities
 */
mozy.modelIdentities.set(Rect.identity,       Rect);
mozy.modelIdentities.set(EdgeSizes.identity,  EdgeSizes);
mozy.modelIdentities.set(Dimensions.identity, Dimensions);

Using models

const dim = new Dimensions();
dim.contentBox.width = 100;
dim.contentBox.height = 40;
dim.padding.left = 10;
dim.padding.right = 10;
dim.borderWidth.top = 1;
dim.borderWidth.bottom = 1;

const jsonStr = JSON.stringify(dim);
console.log(jsonStr);

Will log:

{
  "identity": "layout.Dimensions",
  "uuid": "7366c996-1f8a-482b-ae36-c8e8b988c75c",
  "contentBox": {
    "identity": "shape.Rect",
    "uuid": "451775cc-3b44-4a3a-b9b3-e7ce110ddf80",
    "x": 0,
    "y": 0,
    "width": 100,
    "height": 40
  },
  "padding": {
    "identity": "layout.EdgeSizes",
    "uuid": "8c128fbb-c7b9-4fba-9cb5-005e5586554b",
    "top": 0,
    "right": 10,
    "bottom": 0,
    "left": 10
  },
  "borderWidth": {
    "identity": "layout.EdgeSizes",
    "uuid": "63a3c87c-9575-4a15-8084-2ba54bd13d38",
    "top": 1,
    "right": 0,
    "bottom": 1,
    "left": 0
  },
  "margin": {
    "identity": "layout.EdgeSizes",
    "uuid": "91ec1d41-3f06-4cf6-8c73-dbd6c8923cab",
    "top": 0,
    "right": 0,
    "bottom": 0,
    "left": 0
  }
}

Restoring the model from data dict:

const data = JSON.parse(jsonStr);
const dim = new Dimensions(data);
console.log(dim.padding.right) // 10

Or, if root constructor is unknown, using the registry:

const data = JSON.parse(jsonStr);
const model = mozy.modelRegistry.getModel(data);
console.log(model.padding.right) // 10

Test

(WIP)

npm test

Changelog

0.5.0

  • Renamed getModelData to getDeepClonedModelData for clarity.
  • Replaced usage of (previous) getModelData with getDataReference some places where deep cloning was unnecessary.
  • Added assigning of previous data in Model.assignData (issue #6).
  • Dependency updates.

0.4.0

  • Bugfix for Issue #2: “Bug: copy replaces identical ...”
  • Removed flag to preserve uuids in Model.copy.
  • Fixed tests for Model.copy.
  • Dev dependency updates.
  • Lint fixes.

0.3.0

  • Issue #2: “Bug: copy replaces identical uuids with different uuids, destroying internal references”
  • Flag to preserve uuids in Model.copy.
  • Tests for Model.copy.
  • Dev env config and dependency updates (eslint, babel, nyc).

0.2.2

  • Factory test fixes.
  • toJSON method for model.

0.2.0

  • Switched indentation from 4 spaces to 2.
  • Merged ModelRegistry and Registry into Registry.
  • Model:
    • Rewrite (simplified).
    • Now extends npm:wolfy87-eventemitter instead of npm:events.
  • Factory:
    • Removed dependencies.
  • Tests
    • More tests.
    • Replaced istanbul coverage with nyc.

License

This software is licensed under the MIT License.