Stores /
只读 stores
a. 基础知识 b. 添加数据 c. 动态属性 d. CSS 样式 e. 嵌套组件 f. HTML 标签 g. 创建一个应用程序 a. 赋值 b. 声明 c. 语句 d. 更新数组和对象 a. Declaring props b. Default values c. 属性传递 a. If blocks b. Else blocks c. Else-if 块 d. Each 块 e. 为 each 块添加 key 值 f. Await 块 a. DOM events b. Inline handlers c. 事件修饰符 d. 组件事件 e. 事件转发 f. DOM 事件转发 a. Text inputs b. Numeric inputs c. 复选框 d. 输入框组绑定 e. 文本域绑定 f. 选择框绑定 g. 选择框的multiple属性 h. Contenteditable的绑定 i. Each 块绑定 j. 媒体标签的绑定 k. 尺寸的绑定 l. This m. 组件绑定 a. onMount b. onDestroy c. beforeUpdate 和 afterUpdate d. tick a. Writable stores b. Auto-subscriptions c. 只读 stores d. stores派生 e. 自定义 stores f. 绑定Store a. Tweened b. Spring a. The transition directive b. Adding parameters c. 出入 d. 自定义 CSS 过渡 e. 自定义 JS 过渡 f. 过渡事件 g. 局部过渡 h. 延时过渡 a. The animate directive a. The use directive b. Adding parameters a. The class directive b. Shorthand class directive a. Slots b. Slot fallbacks c. Named slots d. Checking for slot content e. Slot 属性 a. setContext and getContext a. <svelte:self> b. <svelte:component> c. <svelte:window> d. <svelte:window>绑定 e. <svelte:body> f. <svelte:head> g. <svelte:options> a. Sharing code b. Exports a. The @debug tag a. Congratulations!
并非所有stores
都需要在其他地方写入,比如,你可能有一个代表鼠标位置或者用户地理位置的stores
,这样的stores
从其他地方写入并无意义,对于这种情况,我们有 只读(readable) stores
。
点击到 stores.js
选项卡, 第一个参数 readable
可以一个是个初始值,也可以为 null
或 undefined
,第二个参数是 start
函数,该函数有个 set
回调方法,并返回一个 stop
函数。 当stores
首次被subscriber 时调用start
函数,stop
则是最后当subscriber被unsubscribes时调用。
export const time = readable ( new Date ( ) , function start ( set ) {
const interval = setInterval ( ( ) => {
set ( new Date ( ) ) ;
} , 1000 ) ;
return function stop ( ) {
clearInterval ( interval) ;
} ;
} ) ;
Show me