0

如果我使用标准的 Sapper 入门程序:

npx degit "sveltejs/sapper-template#rollup" my-app
npx degit "sveltejs/sapper-template#webpack" my-app
cd my-app
npm install
npm run dev & open http://localhost:3000

我有“巨大的成功”。在我的 Svelte 应用程序中,我使用 rxfire 来查询我的数据库,所以有一个包含初始值的 RxJS BehviourSubject,一旦加载了数据库信息,它就会更新。这在 Svelte 中效果很好,但 Sapper SSR 版本会阻塞。

如果我按如下方式更改示例 Sapper 应用程序:

<script>
 import { BehaviorSubject } from 'rxjs';

 let title$ = new BehaviorSubject('Great success!');
 title$.set = title$.next;
</script>

<!-- ... -->

<h1>{ $title$ }</h1>

我明白了:

500

store.subscribe(...) is not a function

TypeError: store.subscribe(...) is not a function
    at get_store_value (/Users/eveland/Documents/Epiphero/Site/apps/test/__sapper__/dev/server/server.js:255:36)
    at create_ssr_component (/Users/eveland/Documents/Epiphero/Site/apps/test/__sapper__/dev/server/server.js:269:103)
    at Object.$$render (/Users/eveland/Documents/Epiphero/Site/apps/test/__sapper__/dev/server/server.js:231:22)
    at Object.default (/Users/eveland/Documents/Epiphero/Site/apps/test/__sapper__/dev/server/server.js:564:204)
    at create_ssr_component (/Users/eveland/Documents/Epiphero/Site/apps/test/__sapper__/dev/server/server.js:406:38)
    at Object.$$render (/Users/eveland/Documents/Epiphero/Site/apps/test/__sapper__/dev/server/server.js:231:22)
    at create_ssr_component (/Users/eveland/Documents/Epiphero/Site/apps/test/__sapper__/dev/server/server.js:562:41)
    at $$render (/Users/eveland/Documents/Epiphero/Site/apps/test/__sapper__/dev/server/server.js:231:22)
    at Object.render (/Users/eveland/Documents/Epiphero/Site/apps/test/__sapper__/dev/server/server.js:239:26)
    at handle_page (/Users/eveland/Documents/Epiphero/Site/apps/test/__sapper__/dev/server/server.js:2936:36)

作为 Svelte 接管并正确渲染页面之前的初始渲染。

为什么我不能在 Sapper 中使用 BehviorSubject?

4

0 回答 0