
Security News
Deno Goes the Way of the Dinosaur
Cloudflare is acquiring Deno’s team, which will provide another year of bug fixes and security updates before ending support for the runtime.
Models and Intents, for your React app. Inspired by Flux.
npm install coherence
var Coherence = require('coherence');
Coherence is provided as a Node module, and has been used with Browserify for client-side code. If you've used another bundling tool for client-side usage, let me know!
Intents describe things that somebody wants to happen in your app. "Somebody" might be you, the programmer, or the user. "Things" might be choosing a background color, sending a message, opening a form, or pre-fetching data from the server.
Intents in Coherence are analogous to Actions and the Dispatcher(s) of Flux.
Intents are defined by a yielding function, which defines any input, and the output payload provided to the intent's subscribers, whenever the Intent is declared.
An popular pattern within the Flux community seems to be of "Action creators". These are a middle ground between Intents, and using a bare Dispatcher, and, I think, a step in the right direction. However, I think they don't go far enough.
Coherence eschews a Dispatcher, and Action creators, in favor of individually subscribable Intents, for the following reasons:
Coherence.Models.// speak.js
var Coherence = require('coherence');
var Speak = Coherence.Intent((words) => {
return words;
});
module.exports = Speak;
// choose-animal.js
var Coherence = require('coherence');
var ChooseAnimal = Coherence.Intent((animalId) => {
return animalId;
});
module.exports = ChooseAnimal;
When something should actually happen in your app, you declare an Intent.
// react component ...
speak: function() {
Speak(this.state.words);
},
Intent subscriptions are the implementations of your application's behavior, in response to Intent declarations.
Speak.subscribe((words) => {
// say something
});
If you'd like to use path-based Intents, you can use
Coherence.LocationFactory to define Intents that will update history, and the
URL, for you.
This allows your app to handle deep-linking, and browser back/forward, using the same patterns used for any other activity in your application.
// navigate.js
var Coherence = require('coherence');
// passing in window enables pushState, replaceState, and onpopstate support,
// for browsers that support those features
var Location = Coherence.Location(window);
module.exports = Location;
Location.Navigate(path)
path to subscribers, and updates the URL via pushState, if enabled.path should be a string.Location.Redirect(path)
path to subscribers, and updates the URL via replaceState, if enabled.path should be a string.Location.subscribe(subscription)
Navigate or Redirect. Subscription is passed a single argument: whatever
path is passed to Navigate or Redirect.Location Intents yield the path to subscribers, so that you can bring your preferred routing solution.
Models define component-bindable information. You can house your business logic here, but anything complex should probably be pushed into classes of your own creation.
For Intent declarations to effect changes in your views:
// animals-model.js
var Model = require('coherence').Model;
var Speak = require('./speak');
var Animals = function(dependencies) {
var getAnimalAsync = dependencies.getAnimalAsync;
var model = Model(function(expose, def) {
// define bindable state
var currentAnimal = expose('currentAnimal');
var said = expose('said');
// define methods to change that state
def('select', function(animalId) {
getAnimalAsync.then(function(animal) {
currentAnimal.push(animal);
});
});
def('say', function(words) {
said.push(words);
});
});
// Intent subscriptions can be set up when you instantiate your model, or
// where ever else it is convenient
Speak.subscribe((words) => {
model.say(words);
});
return model;
};
module.exports = Animals;
var animalStore = require('./animal_store').instance;
var Speak = require('./speak');
var animals = require('./animals-model').instance;
var AnimalView = React.createClass({
componentWillMount: function() {
this.animalBindings = animals.ReactBindings(this, animals, {
animalData: 'currentAnimal',
animalSays: 'says',
});
},
componentWillUnmount: function() {
this.animalBindings.unbind();
},
render: function() {
return (
<div>
<button onClick={this.saySomething}>Make Animal Say "something"</button>
<AnimalData data={this.state.animalData} />
<p>Animal says: {this.state.animalSays}</p>
</div>
);
},
saySomething: function() {
Speak('something');
},
});
Within the context of a React class definition:
this.bindings = model.ReactBindings(this, bindMap)
this is the React componentbindMap can be either be
exposethis.bindings.unbind()
model.ReactBindings. Call this from
componentWillUnmountAdd or modify tests to reflect the change you want.
Run them with npm test, and update the code in src/ till your tests pass.
Running the tests will run npm run compile, which outputs the code as ES5,
polyfilled via core-js.
FAQs
Flux-inspired Models and Intents, for React apps
We found that coherence 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.

Security News
Cloudflare is acquiring Deno’s team, which will provide another year of bug fixes and security updates before ending support for the runtime.

Security News
Anthropic’s free OSS Scanner uses Mythos and other Claude models to find open source vulnerabilities and send maintainers reports with proposed fixes.

Security News
On Front Lines’ Early Adopters: CISO podcast, Andrew Becherer shares lessons from Datadog, weighs the long-term costs of AI-built tools, and explains how founders can actually gain a CISO’s trust.