
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
flux-common-store
Advanced tools
Flux Common Store
npm install --save-dev flux-common-store
CHANGE_EVENT
(change)Constant event name, equals change
emitChange()
Emits CHANGE_EVENT
addChangeListener(callback)
: unsubscribeFunctionAdds callback
listener for CHANGE_EVENT and returns unsubscribe
function
removeChangeListener(callback)
Alternative way to unsubscribe from CHANGE_EVENT.
WARN For safety reasons, use unsubscribe
function returned by addChangeListener
instead
import FluxCommonStore from 'flux-common-store';
import Dispatcher from '../Dispatcher';
import Constants from '../Constants';
let todos = {};
const create = text => {
const id = Date.now();
todos[id] = {id: id, complete: false, text: text};
};
const destroy = id => delete todos[id];
const TodoStore = {
...FluxCommonStore,
getAll() {
return todos;
}
};
TodoStore.dispatcherIndex = Dispatcher.register(({actionType, payload}) => {
switch (actionType) {
case Constants.TODO_CREATE:
const text = payload.text.trim();
if (text !== '') {
create(text);
TodoStore.emitChange();
}
break;
case Constants.TODO_DESTROY:
destroy(payload.id);
TodoStore.emitChange();
break;
default:
// Empty
}
return true;
});
export default TodoStore;
import TodoStore from '../stores/TodoStore';
const TodoApp = React.createClass({
getInitialState() {
return {todos: TodoStore.getAll()};
},
componentDidMount() {
// Subscribe to TodoStore changes which returns `unsubscribe` function
this.unsubscribe = TodoStore.addChangeListener(this.onChange);
},
componentWillUnmount() {
this.unsubscribe();
},
onChange() {
this.setState({todos: TodoStore.getAll()});
},
render() {
return (
<ul>
{this.state.todos.map(todo => <li key={todo.id}>{todo.text}</li>)}
</ul>
);
}
});
export default TodoApp;
MIT
FAQs
Common Flux Store
We found that flux-common-store demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.