refract

所属分类:前端开发
开发工具:TypeScript
文件大小:0KB
下载次数:0
上传日期:2023-07-12 02:41:12
上 传 者sh-1993
说明:  利用 React编程的强大功能来增强您的组件,
(Harness the power of reactive programming to supercharge your components,)

文件列表:
.editorconfig (64, 2022-01-05)
.prettierrc (66, 2022-01-05)
.travis.yml (118, 2022-01-05)
CHANGELOG.md (6685, 2022-01-05)
CODE_OF_CONDUCT.md (3251, 2022-01-05)
CONTRIBUTING.md (4602, 2022-01-05)
LICENSE (1077, 2022-01-05)
base/ (0, 2022-01-05)
base/__tests__/ (0, 2022-01-05)
base/__tests__/inferno/ (0, 2022-01-05)
base/__tests__/inferno/callbag/ (0, 2022-01-05)
base/__tests__/inferno/callbag/index.tsx (5689, 2022-01-05)
base/__tests__/inferno/jest.config.js (345, 2022-01-05)
base/__tests__/inferno/most/ (0, 2022-01-05)
base/__tests__/inferno/most/index.tsx (5763, 2022-01-05)
base/__tests__/inferno/rxjs/ (0, 2022-01-05)
base/__tests__/inferno/rxjs/index.tsx (5680, 2022-01-05)
base/__tests__/inferno/test.config.js (129, 2022-01-05)
base/__tests__/inferno/tsconfig.json (185, 2022-01-05)
base/__tests__/inferno/xstream/ (0, 2022-01-05)
base/__tests__/inferno/xstream/index.tsx (5689, 2022-01-05)
base/__tests__/preact/ (0, 2022-01-05)
base/__tests__/preact/callbag/ (0, 2022-01-05)
base/__tests__/preact/callbag/index.tsx (2390, 2022-01-05)
base/__tests__/preact/jest.config.js (345, 2022-01-05)
base/__tests__/preact/most/ (0, 2022-01-05)
base/__tests__/preact/most/index.tsx (2381, 2022-01-05)
base/__tests__/preact/rxjs/ (0, 2022-01-05)
base/__tests__/preact/rxjs/index.tsx (2381, 2022-01-05)
base/__tests__/preact/test.config.js (132, 2022-01-05)
base/__tests__/preact/tsconfig.json (173, 2022-01-05)
base/__tests__/preact/xstream/ (0, 2022-01-05)
base/__tests__/preact/xstream/index.tsx (2400, 2022-01-05)
base/__tests__/react/ (0, 2022-01-05)
base/__tests__/react/callbag/ (0, 2022-01-05)
... ...


Handle your component effects and side-effects in a clear and declarative fashion
by using asynchronous data streams (reactive programming).


Why? · Install · The Gist · Learn · Contribute · Discuss


Build MIT License Styled with Prettier


* **Decentralised**: attach effects and side-effects to your components, for better code splitting results * **Gradual**: use on an existing component today, throughout your app tomorrow * **Reactive**: leverage the power and benefits of reactive programming * **Tiny**: less than 2Kb minified and gzipped * **Typed**: written in TypeScript, fully typed integrations * **Universal**: supports React, React Native, Inferno and Preact Refract makes reactive programming possible in React, React Native, Preact and Inferno, with only a single higher-order component or a single hook! You can choose to start using a tiny bit of reactive programming, or go full reactive. Refract allows you to: * [Manage side effects](https://refract.js.org/usage/getting-started) like API calls, analytics, logging, etc. * [Manipulate, replace and inject props](https://refract.js.org/usage/pushing-to-props), you can even [fully replace Redux `connect` HoC](https://refract.js.org/recipes/replacing-connect) * [Handle state](https://refract.js.org/recipes/handling-state) * [Render components](https://refract.js.org/usage/rendering-components) We also provide a Redux integration, which can serve as a template for integrations with other libraries. With a single HoC, you can fully replace libraries like [recompose](https://github.com/acdlite/recompose), [redux-observable](https://redux-observable.js.org/), and [react-redux](https://github.com/reduxjs/react-redux) to name a few! # Why? Component-based architecture and functional programming have become an increasingly popular approach for building UIs. They help make apps more predictable, more testable, and more maintainable. However, our apps don't exist in a vacuum! They need to handle state, make network requests, handle data persistence, log analytics, deal with changing time, and so on. Any non-trivial app has to handle any number of these effects. Wouldn't it be nice to cleanly separate them from our apps? Refract solves this problem for you, by harnessing the power of reactive programming. [For an in-depth introduction, head to `Why Refract`.](https://refract.js.org/introduction/why-refract) # Installation Refract is available for a number of reactive programming libraries. For each library, a Refract integration is available for React, Inferno, Preact and Redux. Available packages: | | [React](https://github.com/facebook/react) | [Inferno](https://infernojs.org/) | [Preact](https://preactjs.com/) | [Redux](https://github.com/reduxjs/redux) | | --- | --- | --- | --- | --- | | **[Callbag](https://github.com/callbag/callbag)** | refract-callbag | refract-inferno-callbag | refract-preact-callbag | refract-redux-callbag | | **[Most](https://github.com/cujojs/most)** | refract-most | refract-inferno-most | refract-preact-most | refract-redux-most | | **[RxJS](https://github.com/reactivex/rxjs)** | refract-rxjs | refract-inferno-rxjs | refract-preact-rxjs | refract-redux-rxjs | | **[xstream](https://github.com/staltz/xstream)** | refract-xstream | refract-inferno-xstream | refract-preact-xstream | refract-redux-xstream | To use the latest stable version, simply `npm install` the package you want to use: ``` npm install --save refract-rxjs ``` # The Gist The example below uses `refract-rxjs` to send data to localstorage. Every time the `username` prop changes, its new value is sent into the stream. The stream debounces the input for two seconds, then maps it into an object (with a `type` of `localstorage`) under the key `value`. Each time an effect with the correct type is emitted from this pipeline, the handler calls `localstorage.setItem` with the effect's `name` and `value` properties. ```js const aperture = component => { return component.observe('username').pipe( debounce(2000), map(username => ({ type: 'localstorage', name: 'username', value: username })) ) } const handler = initialProps => effect => { switch (effect.type) { case 'localstorage': localstorage.setItem(effect.name, effect.value) return } } const WrappedComponent = withEffects(aperture, { handler })(BaseComponent) ``` The example demonstrates uses the two building blocks used with Refract - an `aperture` and a `handler` - and shows how they can be integrated into a React component via the `withEffects` higher-order component. ### Aperture An `aperture` controls the streams of data entering Refract. It is a function which observes data sources within your app, passes this data through any necessary logic flows, and outputs a stream of `effect` values in response. ### Handler A `handler` is a function which causes side-effects in response to `effect` values. # Learn Refract ## Documentation Documentation is available at [refract.js.org](https://refract.js.org). We aim to provide a helpful and thorough documentation: all documentation files are located on this repo and we welcome any pull request helping us achieve that goal. ## Examples We maintain and will grow over time a set of examples to illustrate the potential of Refract, as well as providing reactive programming examples: [refract.js.org/examples](https://refract.js.org/examples). Examples are illustrative and not the idiomatic way to use Refract. Each example is available for the four reactive libraries we support (RxJS, xstream, Most and Callbag), and we provide links to run the code live on [codesandbox.io](https://codesandbox.io). All examples are hosted on this repo, and we welcome pull requests helping us maintaining them. # Contributing ### Guidelines We welcome many forms of contribution from anyone who wishes to get involved. Before getting started, please read through our [contributing guidelines](CONTRIBUTING.md) and [code of conduct](CODE_OF_CONDUCT.md). # Links ### Logo [The Refract logo is available in the Logo directory](/logo/). ### License [Refract is available under the MIT license.](LICENSE) ### Discuss [Everyone is welcome to join our discussion channel - `#refract` on the Reactiflux Discord server.](https://discord.gg/fqk86GH) ### Talks * [ReactiveConf 2018 - Thomas Roch: **Be More Functional and Reactive in React**](https://www.youtube.com/watch?v=c8p9o4rxcYk) * [ReactiveConf 2018 - **AMA w/ Thomas Roch**](https://www.youtube.com/watch?v=liqHgQz8Ar0) ### Articles * [The introduction to Reactive Programming you've been missing](https://gist.github.com/staltz/868e7e9bc2a7b8c1f754) by [@andrestaltz](https://twitter.com/andrestaltz) * [SurviveJS Interview with Thomas Roch - Refract: Manage Component Side Effects the Reactive Way](https://survivejs.com/blog/refract-interview/) * [How we harnessed the power of reactive programming with Refract](https://medium.freecodecamp.org/how-we-harnessed-the-power-of-reactive-programming-with-refract-87f269ac779e)

近期下载者

相关文件


收藏者