javascript - Using xstate, is it possible to configure an event that is applicable under all states and is handled in the same w
- c - Solaris 10 make Error code 1 Fatal Error when trying to build python 2.7.16 - Stack Overflow 推荐度:
- javascript - How to dismiss a phonegap notification programmatically - Stack Overflow 推荐度:
- javascript - Get the JSON objects that are not present in another array - Stack Overflow 推荐度:
- javascript - VS 2015 Angular 2 import modules cannot be resolved - Stack Overflow 推荐度:
- javascript - Type 'undefined' is not assignable to type 'menuItemProps[]' - Stack Overflow 推荐度:
- 相关推荐
I am new to xstate, and I'm trying to use it in an application where a user can request different things in an application, based on parent state and/or sub-state. However, there are some requests that the user should be able to make, no matter what state/sub-state the app is in. The response to those events is the same, no matter what the previous state was. How can I configure this event, so that I don't have to repeat define it under all states/sub-states?
I am new to xstate, and I'm trying to use it in an application where a user can request different things in an application, based on parent state and/or sub-state. However, there are some requests that the user should be able to make, no matter what state/sub-state the app is in. The response to those events is the same, no matter what the previous state was. How can I configure this event, so that I don't have to repeat define it under all states/sub-states?
Share Improve this question edited Apr 23, 2020 at 19:33 curiousWebDev asked Apr 23, 2020 at 17:56 curiousWebDevcuriousWebDev 351 silver badge4 bronze badges1 Answer
Reset to default 7Yes - the algorithm for choosing transitions is similar to DOM event propagation, in that it searches from leaf nodes to root node.
You can define transitions on the root node (top-level) which will be handled in any state naturally:
import { createMachine } from 'xstate';
const machine = createMachine({
// ...
// top-level transitions
on: {
ESC: {/* ... */}
},
states: {
// ...
someState: {
on: {
ESC: {/* override top-level transition */}
}
}
}
});
- 思科宣布27亿美元收购安全软件厂商Sourcefire
- 微软推Surface平板 成硬件合作伙伴竞争对手
- 苹果兜售没用软件脸不红心不跳
- android - Segmentation Fault at start up of Maui App - Stack Overflow
- c# - Unity new input system generating multiple events - Stack Overflow
- eslint - How to have 2 no-restricted-globals rules with different severity? - Stack Overflow
- Flutter iOS UrlLauncher EXC_BAD_ACCESS - Stack Overflow
- tracking - Add custom hand gestures in three.js - Stack Overflow
- laravel - PHP Filament header action button label not toggling correctly - Stack Overflow
- android - Slow screen value detection using root access and uiautomator in Kotlin – Optimization help needed - Stack Overflow
- node.js - Test backend functionality nodespostman error - Stack Overflow
- c++ - inlining failed in call to ‘always_inline’ ‘vld1q_u16’ - cross compiling Node.js for armv6 - Stack Overflow
- How to work with output of tsdisplay (capturemodify plots produced by it) in R - Stack Overflow
- In Visual Studio 2022, Can not export and import new Project Template - Stack Overflow
- swift - How to set axis order in AxisMarks in SwiftUI Chart view - Stack Overflow
- node.js - How to Deploy an Angular 19 SSR App on AWS Amplify? - Stack Overflow
- php - The update and destroy parameters cannot be used in CRUD Laravel 11 - Stack Overflow