{"id":13525265,"url":"https://github.com/xialvjun/preact-flyd","last_synced_at":"2025-10-15T22:31:27.436Z","repository":{"id":57329459,"uuid":"63354835","full_name":"xialvjun/preact-flyd","owner":"xialvjun","description":"Inspired by theadam/react-flyd","archived":false,"fork":false,"pushed_at":"2017-01-14T05:01:21.000Z","size":17,"stargazers_count":11,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-15T19:37:25.437Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"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/xialvjun.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}},"created_at":"2016-07-14T17:07:57.000Z","updated_at":"2023-03-14T01:04:22.000Z","dependencies_parsed_at":"2022-09-14T18:52:22.485Z","dependency_job_id":null,"html_url":"https://github.com/xialvjun/preact-flyd","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xialvjun%2Fpreact-flyd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xialvjun%2Fpreact-flyd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xialvjun%2Fpreact-flyd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xialvjun%2Fpreact-flyd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xialvjun","download_url":"https://codeload.github.com/xialvjun/preact-flyd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236646300,"owners_count":19182633,"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":[],"created_at":"2024-08-01T06:01:17.251Z","updated_at":"2025-10-15T22:31:22.171Z","avatar_url":"https://github.com/xialvjun.png","language":"JavaScript","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"preact-flyd\n=========================\n\nInspired by [theadam/react-flyd](https://github.com/theadam/react-flyd)\n\nAllows for flyd streams to be embedded directly into JSX, and to update content when the streams fire events.\n\n### List Example\n\n```jsx\nimport { render } from 'preact';\nimport { h } from 'preact-flyd';\nimport { stream, scan, merge} from 'flyd';\n\nlet items$ = stream([1,2,3,4,5,])\n\nfunction List() {\n  return (\n    \u003cdiv\u003e\n      \u003cdiv\u003e\n        \u003cbutton id=\"plus\" onClick={e =\u003e items$(items$().concat(Math.random()))}\u003e+\u003c/button\u003e\n      \u003c/div\u003e\n      \u003cul\u003e\n        {items$.map(items =\u003e items.map(item =\u003e \u003cli key={item}\u003e{item}\u003c/li\u003e))}\n      \u003c/ul\u003e\n    \u003c/div\u003e\n  );\n}\n\nrender(\u003cList /\u003e, document.getElementById('app'));\n```\n\n### Several Concept:\n\n**Self Control Element**\na `self control element` means a valid vnode stream like: `{item$.map(item =\u003e \u003cdiv\u003e{item}\u003c/div\u003e)}`. In fact, it runs like this:\n\n```jsx\n\u003cdiv\u003e\n  {item$.map(item =\u003e \u003cdiv\u003e{item}\u003c/div\u003e)}\n\u003c/div\u003e\n\n// will be like\n\nclass ReactiveClass extends Component {\n  ...\n  some lifecycle methods to manage the stream as state\n  ...\n  render() {\n    return \u003cdiv {...this.props}\u003e{this.state.item}\u003c/div\u003e\n  }\n}\n\u003cdiv\u003e\u003cReactiveClass /\u003e\u003c/div\u003e\n```\n\nSince `render` returning a string is accepted in `preact`, a string stream is also be treated as a self control element.\n\n**Parent Control Element**\na `parent control element` means a not valid vnode stream like: `{list$.map(list =\u003e list.map(item =\u003e \u003cli key={item}\u003e{item}\u003c/li\u003e))}`. In fact, it runs like:\n```jsx\n\u003cul\u003e\n  {list$.map(list =\u003e list.map(item =\u003e \u003cli key={item}\u003e{item}\u003c/li\u003e))}\n\u003c/ul\u003e\n\n// will be like\n\nclass ReactiveClass extends Component {\n  ...\n  some lifecycle methods to manage the stream as state\n  ...\n  render() {\n    return \u003cul\u003e{this.state.children}\u003c/ul\u003e // we have change the children from a stream to it's value\n  }\n}\n\u003cReactiveClass /\u003e\n```\n\nAnd of course, `self control element` consume less than `parent control element`, but just a little. You needn't worry about it too much.\n\n### IMPORTANT\n\n~~use streams created in render method rather than outter streams... Just see the example `use_streams_created_in_render_rather_than_out_of_it`~~\n\nTerribly sorry about above description, it's wrong. I must be drunk when I wrote it even though I do not drink alcohol. Well, in fact, what I want to notice you is **BE CAREFUL OF MEMORY LEAKING**.\n\nThere is an example. Some tips is:\n\n1. Don't transform the stream's component type:\n\n```jsx\na$(\u003cdiv /\u003e)\n\u003cdiv\u003e{a$}\u003c/div\u003e   \n// now, a$ will be treated as a self control element, then you can\na$('abc')\na$(\u003cspan /\u003e)\n// but you cann't\na$(1)\na$([1,2,3])\na$([\u003cdiv\u003e\u003c/div\u003e, \u003cdiv\u003e\u003c/div\u003e])\n```\n\n    the rule is: the init value will define the stream's component type. If it's null, string, preact vnode, it's a self control element. Otherwise, it's parent control element. A self control element can only has valid value(null, string, vnode), but a parent control element can has any type value.\n    \n2. Be careful of memory leaking:\n    \n    \n    A self control element stream can be created in `render` method with just one `stream.map`(no more than one level). But a parent control element must be created outside of `render`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxialvjun%2Fpreact-flyd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxialvjun%2Fpreact-flyd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxialvjun%2Fpreact-flyd/lists"}