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

bloxx

v1.0.4

Published

Immutable JavaScript Models for any datastore.

Downloads

9

Readme

B L O X X

JavaScript Models for podjs compliant datastores.

NPM

npm version

BLOXX Models are not part of any larger MVC framework. Just plain JavaScript data structures with a built in persistence API. Designed to work in both the Browser (IE9+) and Node.js.

Built by @kixxauth

API

#fetch(options)

Fetches an object from the datastore. The difference from #load is that #fetch() will return null instead of raising an exception if the object cannot be found in the store.

Returns a resolved Promise for a new instance of the same model type. If the object cannot be found, the returned promise will resolve to null.

The options object will be passed through to the underlying store.

Character.create({id: 'spider-man'})
  .fetch()
  .then(function (character) {
    console.log(character.name); // 'Spider Man'
  });

Character.create({id: 'foobar'})
  .fetch()
  .then(function (character) {
    console.log(character === null); // true
  });

#load(options)

Loads an object from the datastore. The difference from #fetch is that #load() will return a rejected Promise instead of null if the object cannot be found in the store.

Returns a resolved Promise for a new instance of the same model type. If the object cannot be found, #load() will return a rejected promise with error code "NOT_FOUND".

The options object will be passed through to the underlying store.

Character.create({id: 'spider-man'})
  .fetch()
  .then(function (character) {
    console.log(character.name); // 'Spider Man'
  });

Character.create({id: 'foobar'})
  .fetch()
  .catch(function (err) {
    console.log(err.code); // 'NOT_FOUND'
  });

#loadHasMany(options)

Fetches related objects from the datstore and loads them into the #hasMany property.

If an options.include Array is present #loadHasMany will only query for the types listed in options.include. If options.include is not present, then #loadHasMany will query for all the hasMany types configured for the Model class.

Series.create({id: 'spectacular-spider-man'})
  .loadHasMany({include: ['Character']})
  .then(function (characters) {
    console.log(characters[0].id); // 'spider-man'
    console.log(characters[0].type); // 'Character'
    console.log(characters[0].name); // 'Spider Man'
  });

#loadBelongsTo(options)

Fetches related objects from the datastore and loads them into the #blongsTo property.

If an options.include Array is present #loadBelongsTo will only query for the types listed in options.include. If options.include is not present, then #loadBelongsTo will query for all the belongsTo types configured for the Model class.

Series.create({id: 'spider-man'})
  .loadBelongsTo({include: ['Series']})
  .then(function (series) {
    console.log(series[0].id); // 'spectacular-spider-man'
    console.log(series[0].type); // 'Series'
    console.log(series[0].title); // 'The Spectacular Spider Man'
  });

#fetchHasMany(options)

Fetches related object IDs from the datastore. The difference from #loadHasMany is that #fetchHasMany() does not hydrate the attributes of the objects, it only returns the base Objects {id: "STRING", type: "STRING"}.

If an options.include Array is present #fetchHasMany will only query for the types listed in options.include. If options.include is not present, then #fetchHasMany will query for all the hasMany types configured for the Model class.

Returns a Promise which resolves to an Array of base Objects. If none are found, the Array will be empty.

Series.create({id: 'spectacular-spider-man'})
  .fetchHasMany({include: ['Character']})
  .then(function (characters) {
    console.log(characters[0].id); // 'spider-man'
    console.log(characters[0].type); // 'Character'
  });

#fetchBelongsTo(options)

Fetches parent object IDs from the datastore. The difference from #loadBelongsTo is that #fetchBelongsTo() does not hydrate the attributes of the objects, it only returns the base Objects {id: "STRING", type: "STRING"}.

If an options.include Array is present #fetchBelongsTo will only query for the types listed in options.include. If options.include is not present, then #fetchBelongsTo will query for all the blongsTo types configured for the Model class.

Returns a Promise which resolves to an Array of base Objects. If none are found, the Array will be empty.

Series.create({id: 'spider-man'})
  .fetchBelongsTo({include: ['Series']})
  .then(function (series) {
    console.log(series[0].id); // 'spectacular-spider-man'
    console.log(series[0].type); // 'Series'
  });

Copyright and License

Copyright: (c) 2016 by Kris Walker (http://www.kixx.name)

Unless otherwise indicated, all source code is licensed under the MIT license. See MIT-LICENSE for details.