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

not-flux

v0.1.10

Published

angular model store that allows you to share data over all instances, as well as storing all models in one location.

Downloads

7

Readme

Not Flux

What is Not Flux

It's a flux library :) Implemented in angular to provide a quick flux pattern without having to worry about using emitChange everywhere

Features

  • Actions and Stores
  • Stores emit clones
  • NO EMIT CHANGE!!
  • Can have private functions/methods

Examples

Creating a store

.factory('SettingsStore', ['NotFlux', function(NotFlux) {
  return NotFlux.createStore({
    myInfo: {hello: 'world'},
    userId: 4,
    _privateData: 2,

    // Prefix methods or data with a _ to keep them off of what actions can bind to
    _myPrivateStuff: function() {

    },

    modifyInfo: function(id, info) {
      this.myInfo.hello = 'bill' + info

      // Emit events through the app!
      this.emit('myEvent', this.myInfo)
    },

    changeUserId: function(id) {
      this.userId = id
    }
  })
}])

Creating actions

.factory('SettingsActions', ['NotFlux', function(NotFlux) {
  return NotFlux.createActions([
    'setUserId',
    'changeInfo'
  ])
}])

Linking Actions to Stores

.factory('SettingsStore', ['NotFlux', 'SettingsActions', function(NotFlux, SettingsActions) {
  return NotFlux.createStore({
    myInfo: {hello: 'world'},
    userId: 4,

    init: function() {
      // We set the action to listen to the
      // changeUserId callback from the store
      SettingsActions.setUserId.listen(this.changeUserId)

      // We can even define multiple handlers
      SettingsActions.changeInfo.listen([this.modifyInfo, this.changeUserId])
    },

    modifyInfo: function(id, info) {
      this.myInfo.hello = 'bill' + info
    },

    changeUserId: function(id) {
      this.userId = id
    }
  })
}])

Linking up the view

// We must load up the store as well as the actions. This is
// so the store can be initialzed! You only
// need to initialize a store in one location
// though it will not effect anything doing so in multiple places
.controller('myCtrl', ['$scope', 'SettingsStore', 'SettingsActions', function($scope, SettingsStore, SettingsActions) {

  // Call bindTo to update the view on changes
  SettingsStore.bindTo($scope, function(data) {
    $scope.userId = data.userId
  })

  $scope.onClick = function() {
    // Call an action which will change the store
    SettingsActions.changeUserId(5)
  }
})

Methods

Store

Outside the definition

.bindTo($scope, cb)

This is for binding to the data of a store. To modify the datastream we can use tranformFn

.data(waitedAttrs)

This allows you to pull a clone of the data from the store. You can optionally pass it a single string or an array of strings to clone it once it's been filled but this required you to set it to null for initialization.

IE.

.factory('MyStore', function() {
  return NotFlux.createStore({
    // We must set these to null or else we can't tell when they get changed!
    myData: null,
    waiting: null,
  
    set: function() {
      this.myData = 'Hello world'
      this.waiting = {hi: 'bill'}
    }
  })
})

// hello.myData will contain the result
$scope.hello = MyStore.data('myData').result

// Sets $scope.myData and $scope.waiting to the data from the store once its resolved
MyStore.data(['myData', 'waiting']).set($scope)

Inside the definition

.init

A method to overload for initialization of the store. Used to bind actions.

init: function() {
  // Set `setUserId` to run store.changedUserId
  SettingsActions.setUserId.listen(this.changeUserId)

  // We can even define multiple handlers
  SettingsActions.changeInfo.listen([this.modifyInfo, this.changeUserId])
},

.transformFn(data)

This is so you can modify the outgoing stream from the store. IE.

NotFlux.createStore({

  // Data received by bindTo will have be +500
  transformFn: function(data) {
    data.userId += 500

    return data
  }
})

.emit(data)

Use this to emit system wide events IE.

NotFlux.createStore({
  myFn: function(data) {
    this.emit('hello', data)
  }
})

$scope.$on('hello', function(data) {
  console.log(data)
})

Actions

Actions.{name}.listen(handler)

Setup a listener for an action