Comments (4)
I wouldn't.
Better make sure the string passed to machine.emit()
is a registered event in the first place.
Here's a line from the choo readme that summarizes why:
We use the require('assert') module from Node core to provide helpful error messages in development. In production you probably want to strip this using unassertify.
Do you feel like there would be a good case for managing invalid transitions internally?
I could imagine two ways this could work. Maybe:
- we could emit an event. a nanostate instance is already an event emitter which means
.on
is already exposed; the pattern should probably be:machine.on('error', ...)
- we could return a list of all possible states so that consumer can run the check in the application code. this comes at the cost of being tiny. maybe it's worth it? i don't know ¯\(ツ)/¯
For now I try to make sure I emit only registered event names.
I hope this helps :)
edit:
found these thoughts on the subject:
from nanostate.
from nanostate.
@vorg hey, yeah - so the idea behind throwing an error here is that you've made a mistake in the logic. In any given scenario, if you hit an invalid transition, there's no good way to recover from that. Which state did you intend to go? Which state should we be in to recover? There's no good answer.
So we throw, and hope a developer spots the mistake and fixes the source.
As per choojs/nanocomponent#43 for use within nanocomponent
, we'll have error boundaries in the (near) future. These are basically try..catch
blocks around all internal methods, calling an optional error
handler if something goes wrong.
Does this make sense?
from nanostate.
I'm going to prioritize that next, should be a fairly easy addition.
from nanostate.
Related Issues (6)
- IE11 Support HOT 1
- Support transition from 'Any' HOT 2
- implementation of hierarchical state HOT 1
- Implementation of History API HOT 3
- Are the .on's not emitting? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nanostate.