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

frint-model

v5.7.2

Published

Model package for Frint

Downloads

664

Readme

frint-model

npm

Model package for Frint

WARNING: This package has been deprecated!

Use frint-data instead.


Guide

Installation

With npm:

$ npm install --save frint-model

Via unpkg CDN:

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.5.0/Rx.min.js"></script>

<script src="https://unpkg.com/frint-model@latest/dist/frint-model.min.js"></script>

<script>
  // available as `window.FrintModel`
</script>

Terminologies

  • Model: An object that holds data, e.g. configuration, customer information, etc.
  • attributes: The actual data in plain object, which is fed to the Model during construction.

Usage

Let's import the necessary function from the library first:

import { createModel } from 'frint-model';

Now we can create our Model:

const Shirt = createModel({
  getColor: function () {
    return this.get('color');
  },
  getSize: function () {
    return this.get('size');
  },
});

Building a new model instance object:

const shirt = new Shirt({
  color: 'blue',
  size: 'medium',
});

const color = shirt.getColor(); // blue
const size = shirt.getSize();   // medium

The model instance can also be observed for changes:

shirt.get$().subscribe(function (shirtAttributes) {
  // triggered when the model had any change
});

shirt.get$('color').subscribe(function (color) {
  // triggered when the model's `color` key changes
});

API

Model

Model

The base Model class. You can extend the base Model class freely to your own like.

Example

import { Model } from 'frint-model';

export default class Shirt extends Model {
  getColor() {
    return this.get('color');
  }

  getSize() {
    return this.get('size');
  }
}

createModel

createModel(extend)

Creates and returns an ES6 compatible class. Useful in non-ES6 compatible environments.

Arguments

  1. extend (Object): An object with the functions to extend the base Model class with.

Returns

Function: ES6 compatible class.

Example

const Shirt = createModel({
  getColor: function () {
    return this.get('color');
  },
  getSize: function () {
    return this.get('size');
  },
});

model

const model = new Model();

The Model instance

model.get

model.get(key)

Arguments

  1. key (String): Can be dot separated, like deep.nested.path. If empty, it returns all the attributes.

Returns

Any: The key's value.

model.set

model.set(key, value)

Sets the value for given key in the model.

Arguments

  1. key (String)
  2. value (Any)

Returns

void.

get$

get$(key)

Streams the model for given key.

Arguments

  1. key (String)

Returns

Observable.