{"id":309888,"date":"2020-09-14T09:00:36","date_gmt":"2020-09-14T09:00:36","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=309888"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=309888","title":{"rendered":"\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c XSTATE \u0434\u043b\u044f VueJS"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/518920\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/4n\/c3\/iz\/4nc3izjd9uuwvmeukvsdqrdkznc.png\"><\/p>\n<p>  \u041c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"https:\/\/xstate.js.org\" rel=\"nofollow\">XState<\/a> \u043e\u0442 David Khourshid \u0434\u043b\u044f \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043b\u043e\u0433\u0438\u043a\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 VueJS 2. XState \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0440\u0430\u0437\u0432\u0438\u0442\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u043e\u0432 \u043d\u0430 JS. \u041d\u0435\u043f\u043b\u043e\u0445\u043e\u0435 \u043f\u043e\u0434\u0441\u043f\u043e\u0440\u044c\u0435 \u0432 \u0442\u0440\u0443\u0434\u043d\u043e\u043c \u0434\u0435\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. <br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u041f\u0440\u0435\u0434\u0438\u0441\u0442\u043e\u0440\u0438\u044f<\/h4>\n<p>  \u0412 \u043c\u043e\u0435\u0439 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 <a href=\"https:\/\/habr.com\/ru\/post\/482250\/\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043a\u0440\u0430\u0442\u043a\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0437\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u043d\u044b \u043c\u0430\u0448\u0438\u043d\u044b \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 (\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u044b) \u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Vue. \u0412 \u043c\u043e\u0435\u043c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434\u0435 \u0431\u044b\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u0430 \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"json\">{     idle: ['waitingConfirmation'],     waitingConfirmation: ['idle','waitingData'],     waitingData: ['dataReady', 'dataProblem'],     dataReady: [\u2018idle\u2019],     dataProblem: ['idle'] } <\/code><\/pre>\n<p>  \u041f\u043e \u0441\u0443\u0442\u0438 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u043f\u0438\u0441\u0430\u043d \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u201c\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u201d \u043c\u0430\u0448\u0438\u043d\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u2014 \u0445\u043e\u0447\u0443 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0432 \u0442\u0430\u043a\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043c\u0430\u0448\u0438\u043d\u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u043d\u0443\u0436\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. <\/p>\n<p>  \u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043d\u0435\u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0441\u043b\u0438 \u043a\u043d\u043e\u043f\u043a\u0430 \u0432 \u0440\u0430\u0437\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u0430 \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u0432 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u041f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0433\u043e\u0440\u043e\u0434\u0438\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f. \u0412\u043c\u0435\u0441\u0442\u043e \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u0430\u0448\u0443.<\/p>\n<p>  \u0418\u0437\u0443\u0447\u0438\u0432 \u0442\u0435\u043e\u0440\u0438\u044e \u043f\u043e \u0440\u043e\u043b\u0438\u043a\u0430\u043c \u0438\u0437 \u042e\u0442\u044e\u0431\u0430, \u0441\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0443\u0436\u043d\u044b \u0438 \u0432\u0430\u0436\u043d\u044b. \u0412 \u0433\u043e\u043b\u043e\u0432\u0435 \u0440\u043e\u0434\u0438\u043b\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u0432\u0438\u0434 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u0438:  <\/p>\n<pre><code class=\"json\">{   idle: {     GET: 'waitingConfirmation',   },   waitingConfirmation: {     CANCEL: 'idle',     CONFIRM: 'waitingData'   },   waitingData: {     SUCCESS: 'dataReady',     FAILURE: 'dataProblem'   },   dataReady: {     REPEAT: 'idle'   },   dataProblem: {     REPEAT: 'idle'   } }<\/code><\/pre>\n<p>  \u0410 \u044d\u0442\u043e \u0443\u0436\u0435 \u043e\u0447\u0435\u043d\u044c \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0442\u043e, \u043a\u0430\u043a \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 XState. \u041f\u043e\u0447\u0438\u0442\u0430\u0432 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0439 \u0434\u043e\u043a\u0443, \u044f \u0440\u0435\u0448\u0438\u043b \u0443\u0431\u0440\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434 \u0432 \u0441\u0430\u0440\u0430\u0439, \u0438 \u043f\u0435\u0440\u0435\u0441\u0435\u0441\u0442\u044c \u043d\u0430 \u0444\u0438\u0440\u043c\u0435\u043d\u043d\u044b\u0439. <\/p>\n<h4>VUE + XState<\/h4>\n<p>  \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f, \u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0434\u043e\u043a\u0443, \u043f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c XState \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442:  <\/p>\n<pre><code class=\"javascript\">import {Machine, interpret} from \u2018xstate\u2019 <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0430\u0448\u0438\u043d\u0443 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430-\u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u0438:  <\/p>\n<pre><code class=\"javascript\">const myMachine = Machine({     id: 'myMachineID',     context: {       \/* some data *\/     },     initial: 'idle',     states: {         idle: {           on: {             GET: 'waitingConfirmation',           }         },         waitingConfirmation: {           on: {             CANCEL: 'idle',             CONFIRM: 'waitingData'           }         },         waitingData: {           on: {             SUCCESS: 'dataReady',             FAILURE: 'dataProblem'           },         },         dataReady: {           on: {             REPEAT: 'idle'           }         },         dataProblem: {           on: {             REPEAT: 'idle'           }         }     } })<\/code><\/pre>\n<p>  \u041f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u2018idle\u2019, \u2018\u2019waitingConfirmation&#8217; \u2026 \u0438 \u0435\u0441\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435 GET, CANCEL, CONFIRM \u2026.<\/p>\n<p>  \u0421\u0430\u043c\u0430 \u043f\u043e \u0441\u0435\u0431\u0435 \u043c\u0430\u0448\u0438\u043d\u0430 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0438\u0437 \u043d\u0435\u0435 \u043d\u0430\u0434\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 interpret. \u0421\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0441\u0435\u0440\u0432\u0438\u0441 \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043c \u0432 \u043d\u0430\u0448 state, \u0430 \u0437\u0430\u043e\u0434\u043d\u043e \u0438 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 current:  <\/p>\n<pre><code class=\"javascript\">data: {     toggleService: interpret(myMachine),     current: myMachine.initialState, }<\/code><\/pre>\n<p>  \u0421\u0435\u0440\u0432\u0438\u0441 \u043d\u0430\u0434\u043e \u0441\u0442\u0430\u0440\u0442\u0430\u043d\u0443\u0442\u044c \u2014 start(), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043c\u044b \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 current:  <\/p>\n<pre><code class=\"javascript\">mounted() {     this.toggleService         .onTransition(state =&gt; {             this.current = state          })         .start();     }<\/code><\/pre>\n<p>  \u0412 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e send, \u0435\u0435 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u0430\u0448\u0438\u043d\u043e\u0439 \u2014 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0435\u0439 \u0441\u043e\u0431\u044b\u0442\u0438\u0439:  <\/p>\n<pre><code class=\"javascript\">methods: {    send(event) {       this.toggleService.send(event);    },   \u2026 } <\/code><\/pre>\n<p>  \u041d\u0443 \u0430 \u0434\u0430\u043b\u044c\u0448\u0435 \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e. \u041f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u043e\u0432\u043e\u043c:   <\/p>\n<pre><code class=\"javascript\">this.send(\u2018SUCCESS\u2019)<\/code><\/pre>\n<p>  \u0423\u0437\u043d\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435:  <\/p>\n<pre><code class=\"javascript\">this.current.value<\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043c\u0430\u0448\u0438\u043d\u044b \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"javascript\">this.current.matches(\u2018waitingData')<\/code><\/pre>\n<p>  C\u043e\u0431\u0435\u0440\u0435\u043c \u0432\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435:<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">Template<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"xml\">&lt;div id=&quot;app&quot;&gt;   &lt;h2&gt;XState machine with Vue&lt;\/h2&gt;   &lt;div class=&quot;panel&quot;&gt;     &lt;div v-if=&quot;current.matches('idle')&quot;&gt;       &lt;button @click=&quot;send('GET')&quot;&gt;         &lt;span&gt;Get data&lt;\/span&gt;       &lt;\/button&gt;     &lt;\/div&gt;     &lt;div v-if=&quot;current.matches('waitingConfirmation')&quot;&gt;       &lt;button @click=&quot;send('CANCEL')&quot;&gt;         &lt;span&gt;Cancel&lt;\/span&gt;       &lt;\/button&gt;       &lt;button @click=&quot;getData&quot;&gt;         &lt;span&gt;Confirm get data&lt;\/span&gt;       &lt;\/button&gt;     &lt;\/div&gt;     &lt;div v-if=&quot;current.matches('waitingData')&quot; class=&quot;blink_me&quot;&gt;       loading ...     &lt;\/div&gt;     &lt;div v-if=&quot;current.matches('dataReady')&quot;&gt;       &lt;div class='data-hoder'&gt;         {{ text }}       &lt;\/div&gt;       &lt;div&gt;         &lt;button @click=&quot;send('REPEAT')&quot;&gt;           &lt;span&gt;Back&lt;\/span&gt;         &lt;\/button&gt;       &lt;\/div&gt;     &lt;\/div&gt;     &lt;div v-if=&quot;current.matches('dataProblem')&quot;&gt;       &lt;div class='data-hoder'&gt;         Data error!       &lt;\/div&gt;       &lt;div&gt;         &lt;button @click=&quot;send('REPEAT')&quot;&gt;           &lt;span&gt;Back&lt;\/span&gt;         &lt;\/button&gt;       &lt;\/div&gt;     &lt;\/div&gt;   &lt;\/div&gt;   &lt;div class=&quot;state&quot;&gt;     Current state: &lt;span class=&quot;state-value&quot;&gt;{{ current.value }}&lt;\/span&gt;   &lt;\/div&gt; &lt;\/div&gt; <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">JS<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">const { Machine, interpret } = XState  const myMachine = Machine({     id: 'myMachineID',     context: {       \/* some data *\/     },     initial: 'idle',     states: {         idle: {           on: {             GET: 'waitingConfirmation',           }         },         waitingConfirmation: {           on: {             CANCEL: 'idle',             CONFIRM: 'waitingData'           }         },         waitingData: {           on: {             SUCCESS: 'dataReady',             FAILURE: 'dataProblem'           },         },         dataReady: {           on: {             REPEAT: 'idle'           }         },         dataProblem: {           on: {             REPEAT: 'idle'           }         }     } \t})    new Vue({   el: &quot;#app&quot;,   data: {   \ttext: '',   \ttoggleService: interpret(myMachine),     current: myMachine.initialState,   },   computed: {    },   mounted() {     this.toggleService         .onTransition(state =&gt; {           this.current = state         })         .start();   },   methods: {     send(event) {       this.toggleService.send(event);     },     getData() {       this.send('CONFIRM')     \trequestMock()       .then((data) =&gt; {              \tthis.text = data.text          \tthis.send('SUCCESS')       })       .catch(() =&gt; this.send('FAILURE'))     },    } })  function randomInteger(min, max) {   let rand = min + Math.random() * (max + 1 - min)   return Math.floor(rand); }  function requestMock() {   return new Promise((resolve, reject) =&gt; {   \tconst randomValue = randomInteger(1,2)   \tif(randomValue === 2) {     \tlet data = { text: 'Data received!!!'}       setTimeout(resolve, 3000, data)     }     else {     \tsetTimeout(reject, 3000)     }   }) } <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u041d\u0443 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0432\u0441\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0442\u0440\u043e\u0433\u0430\u0442\u044c \u043d\u0430 <a href=\"https:\/\/jsfiddle.net\/Rollroll\/s89hfm1q\/\" rel=\"nofollow\">jsfiddle.net<\/a><\/p>\n<h4>Visualizer<\/h4>\n<p>  XState \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u2014 <a href=\"https:\/\/xstate.js.org\/viz\/\" rel=\"nofollow\"> Visualizer <\/a>. \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e \u0432\u0430\u0448\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u044b. \u0418 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u043e \u0438 \u043f\u043e\u0449\u0435\u043b\u043a\u0430\u0442\u044c \u043f\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u043c \u0438 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u044b. \u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0430\u0448 \u043f\u0440\u0438\u043c\u0435\u0440:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/fh\/_7\/kq\/fh_7kq0d-idmdtvsacm4xch3dac.png\"><\/p>\n<h4>\u0418\u0442\u043e\u0433<\/h4>\n<p>  XState \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 VueJS. \u042d\u0442\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043b\u0438\u0448\u043d\u0435\u0433\u043e \u043a\u043e\u0434\u0430. \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u044f \u043c\u0430\u0448\u0438\u043d\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u043d\u043e \u044f \u0443\u0436\u0435 \u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u0438 \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u041f\u043e\u043b\u0435\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439.<\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u044b\u0439 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u043d\u0435 \u0435\u0433\u043e \u043f\u043e\u043a\u0430 \u0445\u0432\u0430\u0442\u0430\u0435\u0442, \u043d\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0435\u0449\u0435 \u043c\u0430\u0441\u0441\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439: <\/p>\n<ul>\n<li>Guarded transitions<\/li>\n<li>Actions (entry, exit, transition)<\/li>\n<li>Extended state (context)<\/li>\n<li>Orthogonal (parallel) states<\/li>\n<li>Hierarchical (nested) states<\/li>\n<li>History<\/li>\n<\/ul>\n<p>  \u0410 \u0435\u0441\u0442\u044c \u0435\u0449\u0435 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 Robot. \u0412\u043e\u0442 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 <a href=\"https:\/\/blog.logrocket.com\/comparing-state-machines-xstate-vs-robot\/\" rel=\"nofollow\">Comparing state machines: XState vs. Robot<\/a>. \u0422\u0430\u043a \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u0430\u0441 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u0430 \u0442\u0435\u043c\u0430, \u0432\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u0447\u0435\u043c \u0437\u0430\u043d\u044f\u0442\u044c\u0441\u044f.<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/518920\/\"> https:\/\/habr.com\/ru\/post\/518920\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/518920\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/4n\/c3\/iz\/4nc3izjd9uuwvmeukvsdqrdkznc.png\"><\/p>\n<p>  \u041c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"https:\/\/xstate.js.org\" rel=\"nofollow\">XState<\/a> \u043e\u0442 David Khourshid \u0434\u043b\u044f \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043b\u043e\u0433\u0438\u043a\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 VueJS 2. XState \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0440\u0430\u0437\u0432\u0438\u0442\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u043e\u0432 \u043d\u0430 JS. \u041d\u0435\u043f\u043b\u043e\u0445\u043e\u0435 \u043f\u043e\u0434\u0441\u043f\u043e\u0440\u044c\u0435 \u0432 \u0442\u0440\u0443\u0434\u043d\u043e\u043c \u0434\u0435\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439.   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-309888","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309888","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=309888"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309888\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=309888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=309888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=309888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}