{"action":"created","issue":{"url":"https://api.github.com/repos/bcherny/undux/issues/19","repository_url":"https://api.github.com/repos/bcherny/undux","labels_url":"https://api.github.com/repos/bcherny/undux/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/bcherny/undux/issues/19/comments","events_url":"https://api.github.com/repos/bcherny/undux/issues/19/events","html_url":"https://github.com/bcherny/undux/issues/19","id":314434124,"number":19,"title":"Question: Is there simple way to cancel the value update when some condition met?","user":{"login":"tpisto","id":226244,"avatar_url":"https://avatars0.githubusercontent.com/u/226244?v=4","gravatar_id":"","url":"https://api.github.com/users/tpisto","html_url":"https://github.com/tpisto","followers_url":"https://api.github.com/users/tpisto/followers","following_url":"https://api.github.com/users/tpisto/following{/other_user}","gists_url":"https://api.github.com/users/tpisto/gists{/gist_id}","starred_url":"https://api.github.com/users/tpisto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tpisto/subscriptions","organizations_url":"https://api.github.com/users/tpisto/orgs","repos_url":"https://api.github.com/users/tpisto/repos","events_url":"https://api.github.com/users/tpisto/events{/privacy}","received_events_url":"https://api.github.com/users/tpisto/received_events","type":"User","site_admin":false},"labels":[{"id":732228124,"url":"https://api.github.com/repos/bcherny/undux/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":{"login":"bcherny","id":1761758,"avatar_url":"https://avatars2.githubusercontent.com/u/1761758?v=4","gravatar_id":"","url":"https://api.github.com/users/bcherny","html_url":"https://github.com/bcherny","followers_url":"https://api.github.com/users/bcherny/followers","following_url":"https://api.github.com/users/bcherny/following{/other_user}","gists_url":"https://api.github.com/users/bcherny/gists{/gist_id}","starred_url":"https://api.github.com/users/bcherny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcherny/subscriptions","organizations_url":"https://api.github.com/users/bcherny/orgs","repos_url":"https://api.github.com/users/bcherny/repos","events_url":"https://api.github.com/users/bcherny/events{/privacy}","received_events_url":"https://api.github.com/users/bcherny/received_events","type":"User","site_admin":false},"assignees":[{"login":"bcherny","id":1761758,"avatar_url":"https://avatars2.githubusercontent.com/u/1761758?v=4","gravatar_id":"","url":"https://api.github.com/users/bcherny","html_url":"https://github.com/bcherny","followers_url":"https://api.github.com/users/bcherny/followers","following_url":"https://api.github.com/users/bcherny/following{/other_user}","gists_url":"https://api.github.com/users/bcherny/gists{/gist_id}","starred_url":"https://api.github.com/users/bcherny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcherny/subscriptions","organizations_url":"https://api.github.com/users/bcherny/orgs","repos_url":"https://api.github.com/users/bcherny/repos","events_url":"https://api.github.com/users/bcherny/events{/privacy}","received_events_url":"https://api.github.com/users/bcherny/received_events","type":"User","site_admin":false}],"milestone":null,"comments":3,"created_at":"2018-04-15T17:19:43Z","updated_at":"2018-04-15T20:57:53Z","closed_at":"2018-04-15T20:57:53Z","author_association":"NONE","body":""},"comment":{"url":"https://api.github.com/repos/bcherny/undux/issues/comments/381437460","html_url":"https://github.com/bcherny/undux/issues/19#issuecomment-381437460","issue_url":"https://api.github.com/repos/bcherny/undux/issues/19","id":381437460,"user":{"login":"bcherny","id":1761758,"avatar_url":"https://avatars2.githubusercontent.com/u/1761758?v=4","gravatar_id":"","url":"https://api.github.com/users/bcherny","html_url":"https://github.com/bcherny","followers_url":"https://api.github.com/users/bcherny/followers","following_url":"https://api.github.com/users/bcherny/following{/other_user}","gists_url":"https://api.github.com/users/bcherny/gists{/gist_id}","starred_url":"https://api.github.com/users/bcherny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcherny/subscriptions","organizations_url":"https://api.github.com/users/bcherny/orgs","repos_url":"https://api.github.com/users/bcherny/repos","events_url":"https://api.github.com/users/bcherny/events{/privacy}","received_events_url":"https://api.github.com/users/bcherny/received_events","type":"User","site_admin":false},"created_at":"2018-04-15T20:57:53Z","updated_at":"2018-04-15T20:57:53Z","author_association":"OWNER","body":"At a high level, I think you have a few options. The simplest is to not use Undux for this, and just call a function to fetch your data:\r\n\r\n```ts\r\n<button onClick={fetchData} />\r\n\r\nasync function fetchData() {\r\n  store.set('result')(await fetchJSON(...))\r\n}\r\n```\r\n\r\nIf you want to ignore multiple clicks issues one after another quickly, you can use an Observable. Something like this:\r\n\r\n```ts\r\nlet subject = new Rx.Subject\r\n\r\n<button onClick={subject.onNext} />\r\n\r\nsubject\r\n  .bufferTime(300)\r\n  .filter(_ => _ % 2)\r\n  .subscribe(fetchData)\r\n```\r\n\r\nAnd if you want, you can use Undux for this, though you introduce a throwaway property to your store (the thing you're trying to model is a *transition* between states, not a *state*):\r\n\r\n```ts\r\n<button onClick={store.set('triggerFetch')()} />\r\n\r\nstore\r\n  .on('triggerFetch')\r\n  .bufferTime(300)\r\n  .filter(_ => _ % 2)\r\n  .subscribe(fetchData)\r\n```\r\n\r\nThis last use case might break if we ever decide to dedupe .set calls in the future (like we already do for React re-renders).\r\n\r\nConceptually, Undux models states, while Redux models Transitions between states. My hunch is that the majority of Redux uses cases actually care about states, not transitions, so Undux's way of looking at it is more natural. If it turns out that transitions are a more common use case (as they are in your case), I may add an API to repurpose an Undux store as a raw emitter. Something like:\r\n\r\n```ts\r\nstore.emit('triggerFetch')\r\n\r\nstore\r\n  .on('triggerFetch')\r\n  .bufferTime(300)\r\n  .filter(_ => _ % 2)\r\n  .subscribe(fetchData)\r\n```\r\n\r\nHope that helps - let me know what you end up going with, or if you come up with another way to model this!"}}
{"actor":{"display_login":"bcherny"}}