如何在Sapper SSR中使用RxJS BehaviorSubject?

时间:2019-06-26 15:00:13

标签: rxjs svelte sapper rxfire

如果我使用标准的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?

0 个答案:

没有答案