{"id":267841,"date":"2015-11-10T01:55:02","date_gmt":"2015-11-09T22:55:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=267841"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=267841","title":{"rendered":"\u0420\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0435\u043c \u043a\u043e\u0434\u044b \u041c\u043e\u0440\u0437\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Rx.js"},"content":{"rendered":"\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/885\/7d1\/da8\/8857d1da8c9347eeb430c9c2c5ccbfa1.png\" \/><\/div>\n<p>  \u0417\u0430\u0434\u0430\u0447\u0430: \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u0441 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b (keyup, keydown) \u2014 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0431\u0443\u043a\u0432\u044b \u0438 \u0441\u043b\u043e\u0432\u0430 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0430\u0437\u0431\u0443\u043a\u0435 \u041c\u043e\u0440\u0437\u0435. \u041e \u0442\u043e\u043c, \u043a\u0430\u043a \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f FRP \u043f\u043e\u0434\u0445\u043e\u0434, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 Rx.js \u2014 \u043d\u0438\u0436\u0435 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c. (\u0417\u0430\u0447\u0435\u043c? Because we can)<br \/>  <a name=\"habracut\"><\/a><\/p>\n<p>  <b>\u0414\u043b\u044f \u043d\u0435 \u0442\u0435\u0440\u043f\u0435\u043b\u0438\u0432\u044b\u0445:<\/b>  <\/p>\n<ul>\n<li>demo \u2014 <a href=\"http:\/\/alexmost.github.io\/morse\/\">http:\/\/alexmost.github.io\/morse\/<\/a><\/li>\n<li>source \u2014 <a href=\"https:\/\/github.com\/AlexMost\/morse\">https:\/\/github.com\/AlexMost\/morse<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<h4>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f<\/h4>\n<p>  \u0414\u0430\u043d\u043d\u0430\u044f \u0434\u0435\u043c\u043a\u0430 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0441\u0438\u043b\u044b <s>\u0434\u0436\u0435\u0434\u0430\u044f<\/s> \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439. Rx \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e \u0434\u0440\u0443\u0433\u043e\u043c\u0443, \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043a\u0430\u043a \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438. \u041e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0441\u0442\u0430\u0442\u0442\u0435\u0439 \u043f\u0440\u043e Rx \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0442\u0430\u043a:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/734\/f51\/149\/734f51149b4f0b1ec570fbddddbd78cc.jpg\" \/><\/div>\n<p>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (\u0441 \u0436\u0438\u0432\u044b\u043c\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0438 \u0441\u0445\u0435\u043c\u0430\u043c\u0438).<\/p>\n<h4>\u041b\u043e\u0433\u0438\u043a\u0430 \u041c\u043e\u0440\u0437\u0435<\/h4>\n<p>  \u0411\u0443\u043a\u0432\u0430 \u0432 \u0430\u0437\u0431\u0443\u043a\u0435 \u041c\u043e\u0440\u0437\u0435 \u2014 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u043b\u0438\u043d\u043d\u044b\u0445 \u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0445 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 (\u0442\u043e\u0447\u0435\u043a \u0438 \u0442\u0438\u0440\u0435), \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u043e\u043c.<\/p>\n<p>  <i>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 (\u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442):<\/i>  <\/p>\n<ol>\n<li>\u0417\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043e\u0434\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438.<\/li>\n<li>\u0414\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0442\u0438\u0440\u0435 \u0440\u0430\u0432\u043d\u0430 \u0442\u0440\u0451\u043c \u0442\u043e\u0447\u043a\u0430\u043c.<\/li>\n<li>\u041f\u0430\u0443\u0437\u0430 \u043c\u0435\u0436\u0434\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u043a\u0430 \u2014 \u043e\u0434\u043d\u0430 \u0442\u043e\u0447\u043a\u0430.<\/li>\n<li>\u041f\u0430\u0443\u0437\u0430 \u043c\u0435\u0436\u0434\u0443 \u0437\u043d\u0430\u043a\u0430\u043c\u0438 \u0432 \u0441\u043b\u043e\u0432\u0435 \u2014 3 \u0442\u043e\u0447\u043a\u0438.<\/li>\n<li>\u041f\u0430\u0443\u0437\u0430 \u043c\u0435\u0436\u0434\u0443 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u2014 7 \u0442\u043e\u0447\u0435\u043a.<\/li>\n<\/ol>\n<p>  \u0417\u0430\u0431\u0435\u0433\u0430\u044f \u0432\u043f\u0435\u0440\u0435\u0434, \u0445\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0434\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u043c\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043b\u0441\u044f \u043d\u0430\u0434 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044a\u044e \u0438 \u00ab\u043d\u0430 \u0433\u043b\u0430\u0437\u00bb \u0432\u0437\u044f\u043b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u0447\u043a\u0438 \u0432 400 \u043c\u0441. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 100% \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u043e\u0440\u0437\u044f\u043d\u043a\u043e\u0439 (\u043d\u0435 \u043f\u044b\u0442\u0430\u0439\u0442\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0432\u043e\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445), \u043d\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043c \u0436\u0435. \u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e 400 \u043c\u0441 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b (\u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0438\u0440\u0435, \u043f\u0430\u0443\u0437\u0430 \u043c\u0435\u0436\u0434\u0443 \u0431\u0443\u043a\u0432\u0430\u043c\u0438 \u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438). \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d \u0442\u0430\u043a, \u0447\u0442\u043e \u0434\u0430\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0441\u0438\u043c\u0432\u043e\u043b(\u0442\u043e\u0447\u043a\u0443, \u0442\u0438\u0440\u0435) \u0438\u0437 \u0431\u0443\u043a\u0432\u044b, \u043d\u043e\u0432\u0443\u044e \u0431\u0443\u043a\u0432\u0443, \u0438\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043b\u043e\u0432\u043e.<\/p>\n<p>  <i> \u2014 \u0427\u0442\u043e? \u0414\u0430 \u044f \u043d\u0430 \u043a\u043e\u043b\u0435\u043d\u043a\u0435 \u0442\u0430\u043a\u043e\u0435 \u0437\u0430 5 \u043c\u0438\u043d\u0443\u0442 \u0438 \u0431\u0435\u0437 Rx \u0441\u0434\u0435\u043b\u0430\u044e<\/i><\/p>\n<h4>\u0412 \u0447\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c?<\/h4>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0434\u0435\u043b\u043e \u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439. \u041a\u043e\u043b-\u0432\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 \u0432 \u0431\u0443\u043a\u0432\u0435 \u043d\u0435\u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u0443\u043a\u0432\u0430 &#8216;A&#8217; \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u2014 \u0442\u043e\u0447\u043a\u0430 \u0438 \u0442\u0438\u0440\u0435 (.-), \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f, \u043a\u0430\u043a &#8216;0&#8217; \u044d\u0442\u043e \u043f\u044f\u0442\u044c \u0442\u0438\u0440\u0435 (&#8212;&#8212;). \u0422\u0430\u043a \u0436\u0435, \u043d\u0435\u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u043a\u0430\u043a \u043e\u0442\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043e\u0442 \u043e\u0434\u043d\u043e\u0439 \u0431\u0443\u043a\u0432\u044b \u0434\u043e \u0434\u0440\u0443\u0433\u043e\u0439. \u041a\u0430\u043a \u043c\u0435\u0436\u0434\u0443 \u044d\u0442\u0438\u043c \u0432\u0441\u0435\u043c \u0434\u0435\u043b\u043e\u043c \u0435\u0449\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u0435\u043b \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u043c\u0435\u0436\u0434\u0443 \u0441\u043b\u043e\u0432\u0430\u043c\u0438?.. \u0414\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c \u0441 \u043a\u0443\u0447\u0435\u0439 callback-\u043e\u0432 \u0438\u043b\u0438 promise \u0438 setTimeout \u0438\u043b\u0438 \u043d\u043e\u0432\u043e\u043c\u043e\u0434\u043d\u044b\u043c async\/await. \u042f \u043d\u0435 \u0445\u043e\u0447\u0443 \u0443\u0431\u0435\u0436\u0434\u0430\u0442\u044c \u0432\u0430\u0441 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0447\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043f\u043e\u0434\u0445\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0448\u0435\u043b\u0441\u044f \u043c\u043d\u0435 \u043f\u043e \u0434\u0443\u0448\u0435.<\/p>\n<h4>\u0414\u0435\u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0438 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u043b\u043e\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 <\/h4>\n<p>  <i> \u2014 Divide et impera !!!<\/i><\/p>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u0435\u0435 \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u043c\u0435\u043b\u043a\u0438\u0435 \u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043f\u043e\u0434\u0437\u0430\u0434\u0430\u0447\u0438 \u0438 \u0440\u0435\u0448\u0438\u0442\u044c \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0437 \u043d\u0438\u0445 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u0441\u0438\u0433\u043d\u0430\u043b\u044b (DOM event-\u044b), \u0430 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0431\u0443\u043a\u0432\u044b \u0438 \u0441\u043b\u043e\u0432\u0430. \u0414\u0430\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0441 \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A1%D0%B5%D1%82%D0%B5%D0%B2%D0%B0%D1%8F_%D0%BC%D0%BE%D0%B4%D0%B5%D0%BB%D1%8C_OSI\">OSI<\/a>. \u041c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0443\u0440\u043e\u0432\u043d\u044f\u043c\u0438, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0432\u044b\u0448\u0435\u0441\u0442\u043e\u044f\u0449\u0435\u0433\u043e \u0441\u043b\u043e\u044f. \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u044e \u0447\u0435\u0442\u043a\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443, \u043d\u043e \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043e \u0432\u0441\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432\u0446\u0435\u043b\u043e\u043c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u044b\u0434\u0435\u043b\u0438\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0441\u043b\u043e\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0435:  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/656\/bc3\/0a1\/656bc30a13614cb88d7c0e7b5ac1979b.png\" \/><\/div>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043a\u0430\u0436\u0434\u044b\u0439 c\u043b\u043e\u0439 \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u0432\u043e\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435 \u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u0441\u043b\u043e\u044e \u0438 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043e \u0432\u0441\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0432\u0446\u0435\u043b\u043e\u043c.<\/p>\n<h4>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430<\/h4>\n<p>  Rx \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u0443\u044e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0438\u0435 keyup-\u044b \u0438 keydown-\u044b \u0432 \u043d\u0435\u043a\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e (Observable) \u0438 \u043e\u043f\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u043d\u0435\u0439 \u043a\u0430\u043a \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445. <\/p>\n<h4>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u00ab\u0442\u043e\u0447\u043a\u0430 \u0438\u043b\u0438 \u0442\u0438\u0440\u0435\u00bb<\/h4>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0438\u043c\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u044c \u0442\u043e\u0447\u043a\u0438 \u0438\u043b\u0438 \u0442\u0438\u0440\u0435. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0432\u0441\u0435\u0445 \u043d\u0430\u0436\u0430\u0442\u0438\u0439 \u043a\u043b\u0430\u0432\u0438\u0448:<\/p>\n<pre><code class=\"javascript\">const keyUps = Rx.Observable.fromEvent(document, 'keyup'); const keyDowns = Rx.Observable.fromEvent(document, 'keydown'); <\/code><\/pre>\n<p>  <a href=\"http:\/\/jsfiddle.net\/AlexMost\/h8yoodpu\/\">\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 jsfiddle <\/a><\/p>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u044b kyeup \u0438 keydown \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043f\u043e \u043f\u0440\u043e\u0431\u0435\u043b\u0443. \u041c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0445 c \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438 filter \u2014 \u044d\u0442\u043e \u0438 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0448 \u043f\u0435\u0440\u0432\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u0441 DOM-event-a\u043c\u0438:<\/p>\n<pre><code class=\"javascript\">const spaceKeyUps = keyUps.filter((data) =&gt; data.keyCode === 32); const spaceKeyDowns = keyDowns.filter((data) =&gt; data.keyCode === 32); <\/code><\/pre>\n<p>  <a href=\"http:\/\/jsfiddle.net\/AlexMost\/66frLx5r\/3\/\">\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 jsfiddle<\/a><\/p>\n<p>  \u0421\u0445\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/def\/733\/2d7\/def7332d7ed648bb8103d8b15ff8c737.png\"\/><br \/>  \u041d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u0432\u044b\u0448\u0435 \u0432\u0438\u0434\u0438\u043c 2 \u0441\u0442\u0440\u0438\u043c\u0430. \u0412\u0435\u0440\u0445\u043d\u0438\u0439 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0432\u0441\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f keydown. \u041d\u0438\u0436\u043d\u0438\u0439 \u0441\u043e\u0437\u0434\u0430\u043d \u043d\u0430 \u0431\u0430\u0437\u0435 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e, \u043d\u043e \u043a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u043a \u043d\u0435\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e filter, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u0442 \u043a\u043e\u0434 \u043d\u0430\u0436\u0430\u0442\u043e\u0439 \u043a\u043b\u0430\u0432\u0438\u0448\u0438. \u0412 \u0438\u0442\u043e\u0433\u0435 \u0438\u043c\u0435\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0441\u0442\u0440\u0438\u043c \u0441 keydown \u043f\u0440\u043e\u0431\u0435\u043b\u0430. \u0412\u044b \u0433\u0434\u0435 \u043d\u0438\u0431\u0443\u0434\u044c \u0432\u0438\u0434\u0435\u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 spaceKeyDown \u0432 DOM api? \u0422\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0435\u0433\u043e \u043d\u0430 \u0431\u0430\u0437\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e DOM event \u0438 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<p>  \u041d\u0430\u0441 \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442, \u043e\u0442\u043a\u0443\u0434\u0430 \u0431\u044b\u043b \u043f\u043e\u043b\u0443\u0447\u0435\u043d \u0441\u0438\u0433\u043d\u0430\u043b (\u043c\u044b\u0448\u044c, \u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043a\u043b\u0430\u0432\u0438\u0448\u0438, \u043c\u0438\u043a\u0440\u043e\u0444\u043e\u043d, \u043a\u0430\u043c\u0435\u0440\u0430), \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0444\u0430\u043a\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b \u043d\u0430\u0447\u0430\u043b\u0441\u044f \u0438\u043b\u0438 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0441\u044f:<\/p>\n<pre><code class=\"javascript\">const signalStarts = spaceKeyDowns.map(() =&gt; &quot;start&quot;); const signalEnds = spaceKeyUps.map(() =&gt; &quot;end&quot;); <\/code><\/pre>\n<p>  <a href=\"http:\/\/jsfiddle.net\/AlexMost\/e25h4hmc\/4\/\">\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 jsfiddle<\/a>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041d\u043e \u043d\u0435 \u0432\u0441\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u0441 signalStarts \ud83d\ude42<\/b><\/p>\n<div class=\"spoiler_text\">\u0415\u0441\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043a\u0430 \u0441 \u0441\u043e\u0431\u044b\u0442\u0438\u0435\u043c keydown. DOM api \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 keydown \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437 \u043f\u0440\u0438 \u0437\u0430\u0436\u0430\u0442\u0438\u0438 \u043a\u043b\u0430\u0432\u0438\u0448\u0438. \u041c\u044b \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u043c \u043b\u0435\u043a\u0433\u043e \u043f\u043e\u0431\u043e\u0440\u043e\u0442\u044c, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"javascript\">const signalStartsRaw = spaceKeyDowns.map(() =&gt; &quot;start&quot;); const signalEndsRaw = spaceKeyUps.map(() =&gt; &quot;end&quot;);  \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0431\u0449\u0438\u0439 \u0441\u0442\u0440\u0438\u043c \u0438\u0437 start \u0438 end. const signalStartsEnds = Rx.Observable.merge(signalStartsRaw, signalEndsRaw).distinctUntilChanged();  \/\/ signal star\/end with toggle logic const signalStarts = signalStartsEnds.filter((ev) =&gt; ev === &quot;start&quot;); const signalEnds = signalStartsEnds.filter((ev) =&gt; ev === &quot;end&quot;); <\/code><\/pre>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0447\u0442\u043e \u0441\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u0434\u0432\u0443\u0445 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0431\u0449\u0438\u0439 \u0441\u0442\u0440\u0438\u043c \u0438\u0437 start \u0438 end (signalStartsEnds) \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a \u043d\u0435\u043c\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>distinctUntilChanged<\/b>. \u041e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c\u0441\u044f. (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e distinctUntilChanged \u2014 <a href=\"https:\/\/github.com\/Reactive-Extensions\/RxJS\/blob\/master\/doc\/api\/core\/operators\/distinctuntilchanged.md\">\u0442\u0443\u0442<\/a>)<\/p>\n<p>  <a href=\"http:\/\/jsfiddle.net\/AlexMost\/mop8qhgu\/1\/\">\u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 jsfiddle<\/a>  <\/div>\n<\/div>\n<p>  \u0414\u0430\u043b\u0435\u0435, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u0438 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435\u043c \u0441\u0438\u0433\u043d\u0430\u043b\u0430, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043a\u0438 \u043a \u043d\u0430\u0448\u0438\u043c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u043c:<\/p>\n<pre><code class=\"javascript\">const signalStarts = signalStartsEnds.filter((ev) =&gt; ev === &quot;start&quot;).timestamp(); const signalEnds = signalStartsEnds.filter((ev) =&gt; ev === &quot;end&quot;).timestamp(); <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u0435\u0436\u0434\u0443 keydown \u0438 keyup. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0442\u0440\u0438\u043c. \u0422\u0430\u043a \u043a\u0430\u043a \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0435 keyup \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0435 \u0434\u0435\u0442\u0435\u0440\u043c\u0435\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e. \u0422\u043e \u0435\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c keydown \u043a\u0430\u043a stream \u0438 \u0437\u0430\u0441\u0435\u043a\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043d\u0430 \u043a\u043b\u0430\u0432\u0438\u0448\u0443, \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0441\u0442\u0440\u0438\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0435\u0440\u043d\u0435\u0442 \u043f\u0435\u0440\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 keyup. \u041e\u0447\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u043e \u0437\u0432\u0443\u0447\u0438\u0442, \u043f\u0440\u043e\u0449\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432 \u043a\u043e\u0434\u0435:<\/p>\n<pre><code class=\"javascript\">const spanStream = signalStarts.flatMap((start) =&gt; {     return signalEnds.map((end) =&gt; end.timestamp - start.timestamp).first(); }); <\/code><\/pre>\n<p>  <a href=\"http:\/\/jsfiddle.net\/AlexMost\/r8djtfpg\/1\/\">\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 jsfiddle<\/a><\/p>\n<p>  \u0421\u0445\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/c52\/ae5\/f2b\/c52ae5f2b51e4fb49a99ea27d40dd402.png\"\/><\/p>\n<p>  \u041d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 t1, t2, t3\u2026 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f. t2 \u2014 t1 \u2014 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041f\u0440\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043a\u0430\u043a: \u00ab\u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u043d\u0430\u0447\u0430\u043b\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u0430, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0442\u0440\u0438\u043c \u0438\u0437 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u0430, \u0436\u0434\u0435\u043c \u0438\u0437 \u043d\u0435\u0433\u043e 1\u0439 \u0441\u0438\u0433\u043d\u0430\u043b, \u0434\u0430\u043b\u0435\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u0438 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435\u043c \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432\u00bb. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u0442\u0440\u0438\u043c \u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432, \u0438 \u043f\u043e \u043d\u0438\u043c \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u043e\u0447\u043a\u0438 \u0438 \u0442\u0438\u0440\u0435:<\/p>\n<pre><code class=\"javascript\">const SPAN = 400; const dotsStream = spanStream.filter((v) =&gt; v &lt;= SPAN).map(() =&gt; &quot;.&quot;); const lineStream = spanStream.filter((v) =&gt; v &gt; SPAN).map(() =&gt; &quot;-&quot;); <\/code><\/pre>\n<p>  \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a \u2014 <a href=\"http:\/\/jsfiddle.net\/AlexMost\/uv4yh11k\/1\/\">\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 jsfiddle<\/a>. \u0423\u0431\u0435\u0440\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0448\u0443\u043c\u0430 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0431\u043e\u043b\u0435\u0435 \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439 <a href=\"http:\/\/jsfiddle.net\/AlexMost\/myxgubz5\/\">\u043a\u043e\u0434<\/a> (\u0441\u0443\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u043c\u043d\u0435\u043d\u0438\u0435, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0435 \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u043e\u0441\u044c \u2014 \u0443 \u0432\u0430\u0441 \u043d\u0435\u0442 \u0434\u0443\u0448\u0438).<\/p>\n<p>  \u0418 \u0432\u043e\u0442 \u043d\u0430\u0448 \u043e\u0431\u0435\u0449\u0430\u043d\u044b\u0439 \u0441\u0442\u0440\u0438\u043c \u0438\u0437 \u0442\u043e\u0447\u0435\u043a \u0438 \u0442\u0438\u0440\u0435:<\/p>\n<pre><code class=\"javascript\">const dotsAndLines = Rx.Observable.merge(dotsStream, lineStream); <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0443\u0436\u0435 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u043c\u0438 \u0441\u0442\u0440\u0438\u043c\u0430\u043c\u0438 \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u0437 \u043d\u0438\u0445 \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0432 \u043d\u0435\u0441\u043e\u043a\u043e\u043b\u044c\u043a\u043e Rx \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0442\u0440\u0438\u043c \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u0431\u0443\u043a\u0432\u0430\u043c\u0438 \u0430 \u043f\u043e\u0442\u043e\u043c \u0438 \u0431\u0443\u043a\u0432\u0443:<\/p>\n<pre><code class=\"javascript\">const letterCodes = dotsAndLines.buffer(letterWhitespaces) \/\/ \u0441\u0442\u0440\u0438\u043c \u0432\u0438\u0434\u0430 [['.', '.', '-'], ['-', '.', '-'] ... ]  const lettersStream = letterCodes.map((codes) =&gt; morse.decode(codes.join(&quot;&quot;))).share() \/\/ \u0441\u0442\u0440\u0438\u043c \u0431\u0443\u043a\u0432 ['A', 'B' ...] <\/code><\/pre>\n<p>  <a href=\"https:\/\/github.com\/AlexMost\/morse\/blob\/master\/src\/dispatcher.js#L52\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a<\/a><br \/>  \u041a\u0440\u0430\u0441\u0438\u0432\u043e \u043d\u0435 \u0442\u0430\u043a \u043b\u0438? \u041d\u0435\u0442? \u0422\u043e\u0433\u0434\u0430 \u0432\u043e\u0442 \u0442\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u043a\u043e\u0442\u0438\u043a\u0430, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0430\u0431\u0440\u0430\u043b \u043a\u043e\u0434\u0430\u043c\u0438 \u0441\u043b\u043e\u0432\u043e \u00abCAT\u00bb:<\/p>\n<pre><code class=\"javascript\">const setCatImgStream = wordsStream.filter((word) =&gt; word == &quot;CAT&quot;).map(setCatImg) <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0443\u0444<\/b><\/p>\n<div class=\"spoiler_text\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/d9a\/9f8\/51b\/d9a9f851bc454237a41bd71b7a177443.png\"\/>  <\/div>\n<\/div>\n<p>  <\/p>\n<h4>\u0412\u044b\u0432\u043e\u0434<\/h4>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043e\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 DOM \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043c\u044b \u043f\u0440\u0438\u0448\u043b\u0438 \u043a \u0431\u043e\u043b\u0435\u0435 \u043e\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u044b\u043c \u0432\u0435\u0449\u0430\u043c (\u0441\u0442\u0440\u0438\u043c\u0430\u043c \u0441 \u0431\u0443\u043a\u0432\u0430\u043c\u0438 \u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438). \u0412 \u043f\u0435\u0440\u0441\u043f\u0435\u043a\u0442\u0438\u0432\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435 \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0430\u0431\u0437\u0430\u0446\u044b, \u043a\u043d\u0438\u0433\u0438 \u0438 \u0442. \u0434. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e Rx \u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u0430\u0442\u044c \u0432\u0430\u0448 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e. \u0412\u0441\u044f \u0432\u0430\u0448\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0435\u043a\u043e\u0435 API \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0439 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0438 \u0442\u0430 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u0430\u043d\u0430. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0443\u043f\u0443\u0441\u0442\u0438\u043b \u0435\u0449\u0435 \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0430\u0435\u0442 \u0432\u0430\u043c Rx \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 (\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0446\u0435\u043f\u043e\u0447\u0435\u043a, \u0447\u0438\u0441\u0442\u043a\u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a). \u041d\u0430\u0434\u0435\u044e\u0441\u044c \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u0445, \u043a\u0442\u043e \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u043e \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0440\u0435\u0448\u0430\u043b\u0441\u044f.<\/p>\n<p>  <i>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u0412\u0441\u0435\u043c \u0424\u041f =)<\/i>               <\/p>\n<div class=\"clear\"><\/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=\"http:\/\/habrahabr.ru\/post\/262343\/\"> http:\/\/habrahabr.ru\/post\/262343\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/885\/7d1\/da8\/8857d1da8c9347eeb430c9c2c5ccbfa1.png\" \/><\/div>\n<p>  \u0417\u0430\u0434\u0430\u0447\u0430: \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u0441 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b (keyup, keydown) \u2014 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0431\u0443\u043a\u0432\u044b \u0438 \u0441\u043b\u043e\u0432\u0430 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0430\u0437\u0431\u0443\u043a\u0435 \u041c\u043e\u0440\u0437\u0435. \u041e \u0442\u043e\u043c, \u043a\u0430\u043a \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f FRP \u043f\u043e\u0434\u0445\u043e\u0434, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 Rx.js \u2014 \u043d\u0438\u0436\u0435 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c. (\u0417\u0430\u0447\u0435\u043c? Because we can)  <\/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-267841","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/267841","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=267841"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/267841\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=267841"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=267841"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=267841"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}