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

data-state

v0.1.0

Published

Fast state based on top of typed arrays.

Downloads

12

Readme

data-state NPM version Build Status

Fast state based on top of typed arrays.

A simple typed array state container that is fast and scalable.

var state = createState({
  type: Float32Array
}, function dispatch (index, value, oldValue) {
  // Handle value changes on the data
})

for (var i = 0; i < 100) {
  state.stage(i, Math.random())
}

state.update()

I might use it in managing coordinates in canvas, and videos/audio processing. Or maybe any time I want a fast/simple Set:

var state = createState()

state.set(0, 123)
state.get(0) === 123

Installation

$ npm install --save data-state

Usage

createState([options], dispatch)

Create state and container for data. Returns state functions.

Parameters

  • options (Object): Options for your state and data.
    • type (TypedArray): A TypedArray interface for the data backing your state. Defaults to Float32Array.
    • data (ArrayBuffer): A buffer to initialize the typed array with. (Note: overrides length if set)
    • length (Number): Alternative to data, initialize empty typed array at specified length. Defaults to 10000.
    • lowSecurity (Boolean): Makes the dump() return state internals. Defaults to false.
  • dispatch (Function): Dispatch function triggered every time you update.

Dispatch

Updates are called on your function like dispatch(index, value, oldValue). This is called by both state.set() and state.update().

Example

var state = createState({
  type: Uint16Array,
  length: 500 // Maximum amount of data.
}, function (i, value, oldValue) {
  // Dispatch on update
})

state.get(index)

Return value at the given index number.

Example

var foo = state({ data: someExistingData })

var value = foo.get(10)

state.set(index, value)

Set value at the given index number. This calls a dispatch after (opposed to state.stage()).

Example

var state = createState({ type: Float32Array })

state.set(0, 100)
state.get(0) === 100

state.set(1, 0.005)

state.stage(index, value)

Stages the setting of value at the given index number. Values are dispatched when state.update() is called.

Example

var state = createState()

state.stage(1, 123)
stage.get(1) !== 123
// Update it, set staged values
stage.update()
stage.get(1) === 123

state.update()

Sets staged values, dispatching them in ascending order of their index numbers.

Example

var state = createState({
  type: Float32Array
}, function dispatch (index, value, oldValue) {
  // Handle value changes on the data
})

for (var i = 0; i < 100) {
  state.stage(i, Math.random())
}

state.update()

state.length()

Get length of state's array.

Example

var state = createState({ length: 10 })

// Get length
state.length() === 10

state.dump()

This only returns null by default. It can be a risk if you do not want access to any of the data below (i.e. passing to plugins). It can be useful for debugging and unit testing though.

Returns an object containing data, staging, dispatch, and options.

Example

var state = createState({ lowSecurity: true })

var internals = state.dump()
internals.staging[0] = 123
internals.data.buffer
internals.dispatch(10, 0.101, 0.001)
// ...

License

MIT © Jamen Marz