Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
A minimalist state machine.
It is available with bower or npm:
bower install ex-machina
npm install ex-machina
Include ex-machina.min.js
to the HTML, and the exMachina
object is now available in the global scope:
<script type="text/javascript" src="/path/to/bower_components/ex-machina/dist/ex-machina.min.js"></script>
Alternately, you can use Browserify or RequireJS to avoid global scoping.
var exMachina = require('ex-machina');
To create a state machine, use the exMachina
factory:
var machine = exMachina({
state1: {
state2: function(payload) {
return <condition>;
}
}
})
You must pass a config object to the state machine factory. It describes all available transitions. In the above example, when state1
is ended, if the given callback for state2
returns true
, the state2
will be activated. The payload is the value returned by the state which is state1
here.
Note: Only one state can be activated at the same time.
When your state machine is created, you must register all states you described into your config object:
machine.state('state1', function(payload) {
// the payload is the value returned by the previous state or
// the initial payload if it is the first state
// you can return a payload.
// if you perform asynchronous operation, return the promise.
// The payload will be the result of the promise
return <new_payload>;
});
To run your state machine, just execute it:
machine('<initial_state>', '<initial_payload>')
.then(function(payload) {
// a final state was reached
}, function(error) {
// an error occurred
});
The state machine triggers some events before and after state activation:
machine.on(machine.PRE_STATE_EVENT, function(data) {
// this is triggered before a state activation
// data looks like { stateName: <something>, payload: <something> }
});
machine.on(machine.POST_STATE_EVENT, function(data) {
// this is triggered after a state activation
// data looks like { stateName: <something>, payload: <something> }
});
Install dependencies:
make install
To rebuild the minified JavaScript you must run: make build
.
During development you can run make watch
to trigger a build at each change.
make test
All contributions are welcome and must pass the tests. If you add a new feature, please write tests for it.
This application is available under the MIT License.
FAQs
A minimalist state machine
We found that ex-machina 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.