
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Event dispatcher for the flux architecture. Provides event composition
through this.waitFor()
and checks for circular dependencies with a small
interface of only 3 functions.
╔═════╗ ╔════════════╗ ╔════════╗ ╔═════════════════╗
║ API ║<──────>║ Middleware ║──────>║ Stores ║──────>║ View Components ║
╚═════╝ ╚════════════╝ ╚════════╝ ╚═════════════════╝
^ │
│ │
╔════════════╗ │
║ Dispatcher ║ │
╚════════════╝ │
^ │
└────────────────────────────────────────┘
$ npm i --save barracks
var barracks = require('barracks');
// Initialize dispatcher.
var dispatcher = barracks({
users: {
add: function(next) {
console.log(user + ' got added');
next();
}
courses: {
get: function(next) {
console.log('Get ' + this.payload);
next();
},
set: function(next) {
console.log('Set ' + this.payload);
next();
}
}
});
// Dispatch an event.
dispatcher('users_add', 'Loki');
// => 'Loki got added'
Initialize a new barracks
instance. The actions
object should contain
functions, namespaced at most one level deep. Returns a function.
// Initialize without namespaces.
var dispatcher = barracks({
user: function() {},
group: function() {}
});
// Initialize with namespaces.
var dispatcher = barracks({
users: {
add: function() {},
remove: function() {}
},
courses: {
get: function() {},
put: function() {}
}
});
barracks()
returns a dispatcher function which can be called to dispatch an
action. By dispatching an action you call the corresponding function from
the dispatcher and pass it data. You can think of it as just calling a
function.
In order to access namespaced functions you can delimit your string with
underscores. So to access courses.get
you'd dispatch the string courses_get
.
// Call a non-namespaced action.
dispatcher('group', [123, 'hello']);
// Call a namespaced action.
dispatcher('users_add', {foo: 'bar'});
Execute another function within the dispatcher before proceeding. Registered
callbacks are always bound to the scope of the dispatcher, so you can just
call this.waitFor
to access the function from within a registered callback.
In the example below users_initalize
will delegate execution to user_add
and
user_listen
before proceeding to execute its own code.
var userStore = require('simple-store')('user');
var socket = require('sockjs-client');
var request = require('request');
// Initialize dispatcher.
var dispatcher = barracks({
users: {
initialize: function(next) {
var arr = ['user_add', 'user_listen'];
this.waitFor(arr, function() {
console.log('initialized');
next();
});
},
add: function(next) {
request('myapi.co/api/users', function(err, res) {
userStore.set(res);
next();
});
},
listen: function(next) {
var sock = new socket('myapi.co/api/socket');
sock.onMessage(console.log);
next();
}
}
});
// Initialize the users store.
dispatcher('users_initialize');
ctx.payload
contains the data provided by dispatcher()
.
var dispatcher = barracks({
users: {
init: function(next) {
console.log(this.payload);
}
}
});
// Initialize the users store.
dispatcher('users_init', 'fooBar');
// -> console.log: 'fooBar'
this.locals
is shared between all (delegated) function calls and acts as the
location to share data between function calls. For example when you retrieve
a token from a store and want to make it available to all subsequent functions.
The payload provided by dispatcher()
is available under this.locals.payload
.
var request = require('request');
// Initialize dispatcher.
var dispatcher = barracks({
users: {
add: function(next) {
request('myapi.co/api/auth', function(err, res) {
this.locals.token = res.token;
next();
});
},
fetch: function(next) {
this.waitFor(['user_add'], function() {
var url = 'myapi.co/me?token=' + this.locals.token;
request(url, handleRequest);
});
function handleRequest(err, res) {
console.log(res);
next();
}
}
}
});
// Get user data from server.
dispatcher('user_fetch');
FAQs
Action dispatcher for unidirectional data flows
The npm package barracks receives a total of 7 weekly downloads. As such, barracks popularity was classified as not popular.
We found that barracks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
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.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.