Package-level declarations
Types
Debounce options
Description: 在Compose中,子组件可以轻易的调用父组件的函数,例如通过 props 参数传递、使用 useContext钩子暴露等。 但是如果我们希望让父组件调用子组件的方法,举个最简单的例子:父组件中的刷新按钮可以刷新子组件的网络请求, 这时候就有点麻烦了。
Interval options
Throttle options
Description: useTimestamp和useTimestampRef的配置项
Properties
By default, memorySaveMap is used for memory persistence. usePersistent is a lightweight encapsulation, you need to provide your own persistence solution globally through PersistentContext.Provider
;
Functions
A nullable version of useGetState
这是一个可空的useState,如果对象的状态可能为空,应该使用它。
function to create an context object.
defaultOption函数通过调用目标配置选项的Options.default函数,创建默认选项。
you should call this function in your PersistentSave fun to notify state update
Observe Ref as State
更符合 Compose 的函数命名方式
This is a hook function that simplifies the use of coroutine scope. It holds the coroutine scope through an object to achieve a usage similar to the run function. Equivalent to scope.launch { }
This hook function accepts a suspend function as a parameter and returns an function(use to execute suspend function). When you call the execution function, the suspend function will be executed within the coroutine scope of the current component.
Description: 进入后台再次回到前台时执行Effect,不同于官方 API,只在再进入时才执行。 第一次渲染(不执行)-> 进入后台在返回(执行)。
A React-ish hook that returns the current value for that context.
Description: useCreation 是 useRef 的替代品 。而相比于 useRef,你可以使用 useCreation 创建一些常量, 这些常量和 useRef 创建出来的 ref 有很多使用场景上的相似, 但对于复杂常量的创建,useRef 却容易出现潜在的性能隐患。
需要注意:Debounce 不返回计算结果,在 Compose 中我们无法使用 Debounce 透传出结算结果,应该使用状态,而非 Debounce 的返回值。 例如我们有一个计算函数,我们应该设置一个状态作为结果的保存。函数计算后的结果,通过调用对应的 setState(state:T)
函数来传递。保证结算结果(状态)与计算解耦。 这样我们的Debounce 就可以无缝接入。
This hook returns a publish function, use that fun to post a event.
Register a subscriber. Note that this subscription function will be removed from the subscription list after the component is uninstalled.
Use front to back effect,contrary to the useBackToFrontEffect behavior, the effect is executed when the App enters the background
Description: Using destructuring declarations on useState can cause closure problems. Using useLatestRef is a solution, but if you call the set function quickly(millisecond level), there will be a problem of state loss.
Description: Alias for rememberUpdatedState
Description: 在compose中使用state需要写一点模板代码,虽然谈不上有多麻烦,但是还是能简化一下的; 返回值是MutableState,可以解构后使用。如果是可空对象需要显示声明:
用于方便的创建派生状态,派生状态不同于普通的MutableState,他是一个只读的状态, 它只会在依赖发生变化时重新计算改变状态,在其他的框架中也称之为计算属性或者计算状态。
用于方便的切换控制组件的可见性