{"id":16823674,"url":"https://github.com/briancavalier/most-behave","last_synced_at":"2025-03-22T03:31:44.803Z","repository":{"id":66856199,"uuid":"76760583","full_name":"briancavalier/most-behave","owner":"briancavalier","description":"Experimental continuous Behaviors for most.js","archived":false,"fork":false,"pushed_at":"2019-12-30T15:06:06.000Z","size":419,"stargazers_count":32,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-18T07:50:40.903Z","etag":null,"topics":["functional-reactive-programming","mostjs","reactive-programming"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/briancavalier.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-18T03:29:34.000Z","updated_at":"2021-09-21T17:43:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"1738261a-4fc8-4ea1-8bdb-2034187e9b38","html_url":"https://github.com/briancavalier/most-behave","commit_stats":{"total_commits":38,"total_committers":2,"mean_commits":19.0,"dds":"0.23684210526315785","last_synced_commit":"c356f362e8562925d320274aba9a61638f8e3aa9"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/briancavalier%2Fmost-behave","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/briancavalier%2Fmost-behave/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/briancavalier%2Fmost-behave/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/briancavalier%2Fmost-behave/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/briancavalier","download_url":"https://codeload.github.com/briancavalier/most-behave/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244902929,"owners_count":20529114,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["functional-reactive-programming","mostjs","reactive-programming"],"created_at":"2024-10-13T11:08:48.131Z","updated_at":"2025-03-22T03:31:44.406Z","avatar_url":"https://github.com/briancavalier.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Behavior\n\n**EXPERIMENTAL** Don't use this for anything real ... yet.\n\nContinuous time-varying values for most.js.  Behaviors are the continuous complement to most.js discrete Event Streams, or, if you prefer, the \"pull\" complement to most.js \"push\" Event Streams.\n\n## Try it\n\nFeedback welcome via [gitter](https://gitter.im/cujojs/most), but seriously, don't use it for anything real yet.\n\n```\nnpm i --save @briancavalier/most-behavior\n```\n\n## Behavior\n\nA Behavior is a continuous value.  In contrast to an Event Stream which has discrete occurrences at particular instants in time, a Behavior's value is defined at all *real number* (not integer) values of time and may vary continuously (or not) over time.\n\nBecause they are defined for all real number values of time, a Behavior must be *sampled* to obtain its value at specific instants in time.  To sample a Behavior, pass it an Event Stream whose occurrences define all the points in time at which the behavior's value should be sampled.\n\nHere's a simple example.  Note that because `clock` is \"pull\", it does no work at the instants between clicks, where it is *not* being sampled.\n\n```js\nimport { time } from '@briancavalier/most-behavior'\nimport { click } from '@most/dom-event'\n\n// A Behavior that always represents milliseconds since the application started\nconst clock = time\n\n// Sample the clock each time the user clicks\nconst timeAtEachClick = sample(clock, click(document))\n```\n\nFor now, [see the examples dir](examples) for more realistic code, how to run a `@most/core` app that integrates behaviors, etc.\n\n## API\n\n### Creating Behaviors\n\n#### time :: Behavior number\n\nA behavior that represents the current time in milliseconds since the application started.\n\n#### always :: a \u0026rarr; Behavior a\n\nCreate a Behavior whose value is always `a`.\n\n#### step :: a \u0026rarr; Stream a \u0026rarr; Behavior a\n\nCreate a Behavior that starts with an initial value and updates to each new value in the Event Stream.\n\n### Transforming Behaviors\n\n#### map :: (a \u0026rarr; b) \u0026rarr; Behavior a \u0026rarr; Behavior b\n\nApply a function to a Behavior at all points in time.\n\n#### apply :: Behavior (a \u0026rarr; b) \u0026rarr; Behavior a \u0026rarr; Behavior b\n\nApply a (time-varying) function to a Behavior at all points in time.\n\n#### liftA2 :: (a \u0026rarr; b \u0026rarr; c) \u0026rarr; Behavior a \u0026rarr; Behavior b \u0026rarr; Behavior c\n\nApply a function to 2 Behaviors at all points in time.\n\n### Sampling Behaviors\n\n#### sample :: Behavior a \u0026rarr; Stream b \u0026rarr; Stream a\n\nSample a Behavior's value at every occurrence of an Event Stream.\n\n#### snapshot :: Behavior a \u0026rarr; Stream b \u0026rarr; Stream [a, b]\n\nSample a Behavior at every occurrence of an event, and compute a new event from the (event, sample) pair.\n\n## Potential APIs\n\nPotentially useful APIs we could add:\n\n### when :: Behavior bool \u0026rarr; Stream a \u0026rarr; Stream a\n\nAllow events only when a Behavior's value is `true`.\n\n### accum :: a \u0026rarr; Stream (a \u0026rarr; a) \u0026rarr; Behavior a\n\nCreate a Behavior with an initial value and an Event Stream carrying update functions.\n\n### scanB :: (a \u0026rarr; b \u0026rarr; a) \u0026rarr; a \u0026rarr; Stream b \u0026rarr; Behavior a\n\nLike scan, but produces a Behavior.  Needs a helpful name ...\n\n### scanB :: (a \u0026rarr; b \u0026rarr; Behavior a) \u0026rarr; Behavior a \u0026rarr; Stream b \u0026rarr; Behavior b\n\nGeneralized scan for Behaviors.  When event occurs, sample Behavior, and apply a function that creates a new Behavior.  Somewhat like `switch`.  Needs a helpful name ...\n\n### count :: Stream a \u0026rarr; Behavior number\n\nCreate a Behavior representing the number of event occurrences.\n\n### switch :: Behavior a \u0026rarr; Stream (Behavior a) \u0026rarr; Behavior a\n\nCreate a Behavior that acts like an initial Behavior and switches to act like each new Behavior that occurs in the Event Stream.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbriancavalier%2Fmost-behave","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbriancavalier%2Fmost-behave","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbriancavalier%2Fmost-behave/lists"}