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

@beef-flux/store

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@beef-flux/store - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

10

lib/actions.d.ts
import Store from "./base-store";
import ActionsManager from './actions/manager';
declare abstract class Actions {
private actions;
protected debug: boolean;
constructor();
__register<T>(actionData: {
setDebug(debug: any): this;
define(actionName: string, cb: (...any: any[]) => any): (...any: any[]) => any;
dispatch(actionName: string, data: any, additionalParams?: any): void;
register<T>(actionData: {
[P in keyof this]?: (...any: any[]) => any;
}, store: Store<T>): void;
private _debug;
}
export default Actions;
export { ActionsManager };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var manager_1 = require("./actions/manager");
exports.ActionsManager = manager_1.default;
var base_store_1 = require("./base-store");
var Actions = /** @class */ (function () {
function Actions() {
var _this = this;
this.actions = {};
this.define = this.define.bind(this);
this.dispatch = this.dispatch.bind(this);
this.register = this.register.bind(this);
this.debug = false;
Object.getOwnPropertyNames(Object.getPrototypeOf(this)).forEach(function (property) {

@@ -15,10 +19,81 @@ if (property === 'constructor' || property.indexOf('__') === 0) {

}
_this[property] = manager_1.default.define(property, _this[property]);
_this[property] = _this.define(property, _this[property]);
});
}
Actions.prototype.__register = function (actionData, store) {
return manager_1.default.register(actionData, store);
Actions.prototype.setDebug = function (debug) {
this.debug = debug;
return this;
};
Actions.prototype.define = function (actionName, cb) {
if (typeof actionName !== 'string') {
console.error("actionName is not a valid string", actionName);
}
if (typeof cb !== 'function') {
console.error("Must pass valid callback for action: ", cb);
}
if (typeof this.actions[actionName] !== 'undefined') {
console.warn('Action with name ' + actionName + ' was already defined, and is now being overwritten');
}
this.actions[actionName] = {
cb: cb,
stores: []
};
var override = function () {
this.dispatch(actionName, arguments);
};
override = override.bind(this);
override.toString = function () {
return actionName;
};
override['original_argument_length'] = cb.length;
return override;
};
Actions.prototype.dispatch = function (actionName, data, additionalParams) {
if (typeof this.actions[actionName] === 'undefined') {
console.warn('Attempting to call non registered action: ' + actionName);
return;
}
this._debug("ACTION.DISPATCH: " + actionName, data);
var cb = this.actions[actionName].cb;
var results = cb.apply(null, data);
this.actions[actionName].stores.forEach(function (storeInfo) {
var store = storeInfo.store;
var cb = storeInfo.cb;
store.stateChange(actionName, cb(results, additionalParams));
});
};
Actions.prototype.register = function (actionData, store) {
for (var actionName in actionData) {
if (typeof this.actions[actionName] === 'undefined') {
console.warn('Store attempting to register missing action: ' + actionName);
continue;
}
this._debug(actionName + " registered for ", store);
this.actions[actionName].stores.push({
store: store,
cb: actionData[actionName]
});
}
this.actions[base_store_1.default.ACTION_SEED + "_" + store.uuid] = {
cb: function (raw) {
return raw;
},
stores: [{
cb: store.__onSeed,
store: store
}]
};
};
Actions.prototype._debug = function () {
var any = [];
for (var _i = 0; _i < arguments.length; _i++) {
any[_i] = arguments[_i];
}
if (!this.debug) {
return;
}
console.debug.apply(null, arguments);
};
return Actions;
}());
exports.default = Actions;
import * as React from 'react';
import { Manager } from './context';
import Actions from 'actions';
export declare const useStore: <T>(store: Store<T>) => T;

@@ -59,3 +60,3 @@ export interface StateHistory<T> {

protected __seedFunctions: any[];
constructor(initialState: Partial<T>);
constructor(initialState: Partial<T>, actions?: Actions);
static subscribe<C, T>(onUpdate: (componentState: C, nextStoreState: T, oldStoreState: T) => Partial<C>): any;

@@ -62,0 +63,0 @@ static subscribeTo<C, T, P extends {

@@ -49,3 +49,4 @@ "use strict";

var Store = /** @class */ (function () {
function Store(initialState) {
function Store(initialState, actions) {
if (actions === void 0) { actions = null; }
this.config = DEFAULT_CONFIG;

@@ -52,0 +53,0 @@ /**

/// <reference types="react" />
import Actions, { ActionsManager } from './actions';
import Actions from './actions';
import Model from './model';

@@ -17,2 +17,2 @@ import Store, { useStore } from './base-store';

export default _default;
export { ActionsManager, SubscribeMap, ContextManager, Schema, useStore };
export { SubscribeMap, ContextManager, Schema, useStore };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var actions_1 = require("./actions");
exports.ActionsManager = actions_1.ActionsManager;
var model_1 = require("./model");

@@ -6,0 +5,0 @@ var base_store_1 = require("./base-store");

{
"name": "@beef-flux/store",
"version": "0.2.5",
"version": "0.2.6",
"description": "Flux compatible state machine",

@@ -34,3 +34,3 @@ "keywords": [

},
"gitHead": "a1f699810b7793b7cf1b8bdfb93b739cda65074f"
"gitHead": "6efd6283e8381e0f0dbc4d5e4384f753a1e58027"
}

@@ -8,5 +8,5 @@ # `beef-flux-store`

```
const russetStore = require('@russet/russet-store');
const russetStore = require('@beef-flux/store');
// TODO: DEMONSTRATE API
```
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