Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cargo-bay

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cargo-bay

A base store for flux applications

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

cargo-bay

cargo bay

A base store for flux applications

Install

npm install cargo-bay

Usage

This is the base store for the storages in your flux application. It will provide the base events you will merge into your store, so you can have a standard interface to listening to those storage updates. This will let you know that the state in your store has changed, and you can call render (or whatever you want) in your view.

#/stores/HelloWorldStore.js

'use strict';

var LCARS = require('lcars');
var CargoBay = require('cargo-bay');
var HelloWorldConstants = require('./../constants/HelloWorldConstants');
var merge = require('amp-merge');

var HelloWorldData = {
  _data: {
    name: "Bob",
    age: undefined
  },
  clonedData: function() {
    return JSON.parse(JSON.stringify(this._data));
  }
};

var _setAge = function(age){
  var data = HelloWorldData.clonedData();
  data.age = age;
  HelloWorldData._data = data;
  return HelloWorldData.clonedData();
};

var HelloWorldStore =  merge(CargoBay, {
  getDataFromStore: function(){
    return HelloWorldData.clonedData();
  }
});

HelloWorldStore.dispatchToken = LCARS.register(function(action){
  switch (action.type){
    case HelloWorldConstants.DemoActions.SET_AGE:
      _setAge(action.data.age);
      HelloWorldStore.emitChange();
      break;
  }
});

module.exports = HelloWorldStore;

In your component

var HelloWorldStore = require('./../stores/HelloWorldStore')

componentDidMount: function() {
  HelloWorldStore.addChangeListener(function(){
    var state = this.getStateFromStores();
    this.setState(state);
  }.bind(this));
},

You can see an example of this in freighter.

Run tests
npm install

npm test

Keywords

FAQs

Package last updated on 18 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc