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

@meteorrn/local

v1.0.3

Published

Store data locally

Downloads

12

Readme

Local

This package allows you to store your data locally (similar to GroundDB for Meteor Web).

This package introduces the Local.Collection, which will mirror the specified remote collection, and store all documents on the device, making your data offline.

Caveats

  • This package (currently) works by creating a second local Mongo Collection. This means you are esentially keeping two copies of each document (that you store locally) in memory. This issue can be mitigated by keeping an "age" or "version" on all your documents, and only publishing documents that have been changed from local
  • This package (currently) does not support the automatic removal/expiry of documents. Once a document has been inserted into the local database, it is there forever (unless you manually call remove on the Local.Collection)

Usage:

import Local from '@meteorrn/local';

const MyLocalCollection = new Local.Collection("name");

MyLocalCollection.find().fetch()

You should use LocalCollection whenever you want to access the stored data. The Local Collection will observe the live collection and automatically update when the live collection does.

Data Loading:

A Local.Collection exposes a property called loadPromise which resolves once local data has been loaded into the collection. You can use this to control loading flow, like so:

const Todos = new Local.Collection("todos");

class Home extends React.Component {
  state = {dataLoading:true};

  componentDidMount() {
    Todos.loadPromise.then(() => {
      this.setState({dataLoading:false});
    }).catch(e => {
      // Uh oh, an error loading the data.
    });
  }
}

Data Grouping

By default, this package stores each collection in its own AsyncStorage field. If you plan to store very large amounts of data in a collection, consider grouping the data. When you specify a certain field, data will be grouped on this field and stored in separate AsyncStorage fields. If you specify a limit, the limit will be applied to individual groups instead of the collection as a whole.

API Docs

Collection(name, options)

Creates a Local Collection that mirrors changes to collection with specified name.

Options:

groupBy (default: null): Specifies a field to organize items on. Items will be grouped into separate AsyncStorage keys by specified limit. If you specifiy a limit, the limit will be applied to each group instead of the collection as a whole

limit (default: -1): Specifies a limit to the number of documents to store. The sort property is required to use this.

sort (default: null): Specifies a sort method to maintain documents by

disableDateParser (default: false): Disables the default behavior when parsing the stringified collection of automatically converting date strings into JS dates

Properties: A Local.Collection is a local Mongo Collection that exposes the following additional properties

loadPromise (Promise): A promise that resolves when the local data has been inserted into the collection. While this will typically only take a few hundred milliseconds, if you have UI that depends on the local data, you may want to use this promise in your loading flow.

Compatability

This package takes advantage of observe and local collections, added in @meteorrn/[email protected].