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

ogre2

v0.4.1

Published

Object Graph engine

Downloads

4

Readme

Ogre

Object Graph Manager

Contents

Overview

Weighing in at ~5kb, gzipped, Ogre is pretty svelte. Built with React in mind, Ogre is a simple graph manager that leverages React's own immutability helpers to update objects without changing the surrounding topography.

Although they are called "immutability helpers," Ogre is not about immutability. It is about highly efficient object equality checks:

shouldComponentUpdate( nextProps, _ ) {
    return this.props.item !== nextProps.item
}

Example:

var data= new Ogre({
    idList: [],
    itemMap: {}
})

data.onChange( function( changedKeys ){ /* Now you know */ } )

var item= { id:'ID1', name:'The First' }

// Both of these mutations will only result in a single
// 'onChange' event on the nextTick.
data.set('itemMap.ID1', item)
data.push('idList', item.id )

data.get('itemMap.ID1') === item // => true

Since the onChange event is accumulated, by default, you could have multiple stores (in a synchronous Flux pattern) all modify a global application state graph (ogre), and only trigger a single render call.

API

new Ogre( initialState={}, options={} )

Options:

| name | description | default | |:---------------|:-------------------------------------------------------|:--------| | maxHistory | Number of old states to remember | 1 | | batchChanges | Batch synchronous mutations into single 'change' event | true | | strict | Throw error when mutating non-existing key paths | true |

If strict is false, Ogre will automatically create all the missing object paths (Rather like mkdir -p does). It will try to deduce the final leaf container type based on the operation being used. For example if using: ogreData.push( 'new.deeply.nested.leaf') Ogre knows that push is for Arrays, so it'll create the leaf container as an Array. By default any elements in between, if missing, will be objects.

get( path:string, defaultValue:any ):any

set( path:string, value:any ):Ogre

scopeTo( path:string ):Ogre

Returns a lightweight 'cursor' object that has the same API as an Ogre object, but is bound to the specified path as the root. If you subscribe to events on cursors, the callbacks will only be triggered when an element of the graph has changed for this path.

getPrevious( path:string, step=0 ):any

Returns data from history. Step 0 is the previous version. If you set the maxHistory to a higher amount than the default of 1, you can get values up to that many steps back.

Note: Stored revisions of the graph are for the whole tree.

merge( path, object )

push( path, array )

unshift( path, array )

splice( path, start, howMany, ...items) {

map( path, fn )

each( path, fn )

forEach( path, fn )

filter( path, fn )

find( path, fn )

indexOf( path, value )

reduce( path, fn, initialValue )

onChange( handlerFn ):function

Returns a function that, when called, will unsubscribe handlerFn from the event. (Use for supporting anonymous, inline callbacks).

offChange( handlerFn )

isUndefined( path )

isNotUndefined( path )

isDefined( path )

isNull( path )

isNotNull( path )

isEmpty( path )

isNotEmpty( path )

isString( path )

isNotString( path )

isArray( path )

isNotArray( path )

isObject( path )

isNotObject( path )

isNumber( path )

isNotNumber( path )

Todo

  • Flesh out API docs.
  • More examples.

Building

Compile from src/ to lib/:

npm run build

Compiles for browser to dist/:

npm run dist

Minify browser build:

npm run minify

Run tests:

npm test

The whole shebang:

npm run all

License

The MIT License (MIT)

Copyright (c) 2014-2015 Elucidata unLTD

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.