React Native Meteor FAQ

There are a few questions that I see pop up on the various blog posts I've written on React Native Meteor. I want to put together an FAQ to, hopefully, help you out and point you in the write direction. This document will be updated over time so please send me anything you feel should be included.

Make sure to point your React Native app to the correct url for your Meteor app

1. 確保你的React Native應(yīng)用指向了正確的Meteor應(yīng)用URL

Meteor automatically knows what your server URL is because it handles the entire stack. Since React Native is purely a client and doesn't have those built-in server bindings you need to inform it of which server you want to connect to, and it change it based on the environment. This will likely be localhost:3000 in development and something like wss://my-fake-app.meteor.com in production. Make sure you're connecting to the correct one before publishing and when debugging.

When I try to subscribe I get an error of INVALID_STATE_ERR, what does this mean?

2. 當(dāng)我嘗試訂閱數(shù)據(jù),我得到一個(gè)錯(cuò)誤INVALID_STATE_ERR府喳,這意味著什么退疫?

This error means you're trying to interact with the DDP/Meteor server before you've actually connected to the server. Make sure that you point to the correct URL of your Meteor server and that you're connection has succeeded before making calls/subscriptions.

How can I identify a user?

3. 我該如何用戶(hù)驗(yàn)證?

If you've authenticated your user via DDP then you'll have access to*this.userId *in publish functions and Meteor.userId() everywhere else. Here's a few articles on authentication with React Native and Meteor

Can I do Hot Code Push?

4. 我能代碼熱重載嗎?

Yes! There are third party tools such as CodePush and AppHub out there to handle this. There are limitations but they're the same limitations you would face with Meteor and Cordova.

If you want to get CodePush integrated check out this article.

You only have to connect to the DDP (Meteor) server once

5. 你只需要連接一次Meteor的DDP服務(wù)器

This one may seem obvious to some of you but for those just getting started know that you only have to connect to the Meteor server once, likely when your app first mounts. Subsequent calls and subscribes will use the existing DDP connection - you don't need to specify a new one prior.

Which DDP Package should I use? Why?

6. 我該使用哪個(gè)DDP擴(kuò)展混驰?為什么昧捷?

This is a tricky one because there are a few options out there currently. Here are a few:

  • ddp.js: This one is quickly becoming my go to for raw interaction with the ddp protocol. It’s actually the one that backs react-native-meteor.
  • react-native-meteor: This is the one I’m really excited about and have been putting some effort behind. It’s a “magic” included DDP client?—?allowing you to use an extremely similar API to what you may be used to with vanilla Meteor. It’s still a work in progress but should definitely stay on your radar.
  • spencercarli/node-ddp-client: This is a stop-gap solution to some of the issues with the *node-ddp-client *that I mention below. It fixes a few bugs, corrects documentation, BUT doesn't use minimongo-cache
  • node-ddp-client: This is the one I’ve used for quite a while. The latest version uses minimongo-cache. Downsides include a few bugs, incorrect documentation, and it’s no longer supported.

What about Minimongo?

7. 那么Minimongo呢?

There are some efforts to replicate minimongo without the browser dependency but I, to be honest, haven't followed it too much as I've preferred to not use it in React Native. The leading contender for a replacement is minimongo-cache. It's also been integrated into react-native-meteor so my opinions on minimongo in React Native may change soon!

Be more conscious of your API and data schema up front - it's harder to update things even with CodePush

8. 加倍關(guān)注你的API和數(shù)據(jù)模式 - 即使用CodePush也相當(dāng)難以更新

When you're developing with Meteor, or the web in general, you've got quite a bit of flexibility. You can publish new features and bug fixes whenever you want and know that the user will have the latest code in their hand the next time they visit your site. The same isn't true for mobile app development - this goes for Objective C, Swift, Java, React Native, etc. You've got to go through some sort of process to update your code... and then you need your user to opt in to updating.

This has gotten easier with the likes of CodePush and AppHub but it's still something to be aware of when developing for React Native. Make sure that you put some time up front designing your data structure and API so that it doesn't bite you later.

What about OAuth?

9. 那么OAuth相關(guān)的呢堤框?

This has been the most requested item... and I've found it to be tough. The existing "magic" OAuth that comes with Meteor doesn't play too well with an external client's OAuth process due to its tight coupling with the browser. I have dived into it a bit and put together a guide for the Google OAuth process here:
React Native Meteor Google OAuth

Do you want me to write a definitive guide on React Native Meteor OAuth with the various OAuth providers? Ping me on Twitter.

Boilerplates

10. 模板

Boilerplates are a great way to get that instant gratification. You may grow out of them later but when you're learning they're extremely valuable and get you a quick win. Here are a few

  • react-native-meteor: This is one I wrote and thus am partial to. It's very bare bones - handling only the DDP connection, basic authentication, and some file structure.
  • react-native-meteor-starter: A bit more in depth than the other but shows you more functionality.

I'm planning to write a book on React Native and Meteor - taking you from design mockups to publishing an iOS app**AND **an Android app to their respective store’s. If you're interested in early access and being part of the feedback process sign up for my email list here.

If you have any questions just respond to one of my newsletter emails and I’ll answer it the best I can. You can also ask me on Twitter.

參考

原文地址:https://medium.com/@spencer_carli/react-native-meteor-faq-919af1db7239#.8sj6u421p

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末域滥,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子蜈抓,更是在濱河造成了極大的恐慌启绰,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,734評(píng)論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件沟使,死亡現(xiàn)場(chǎng)離奇詭異委可,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)腊嗡,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,931評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門(mén)着倾,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人燕少,你說(shuō)我怎么就攤上這事卡者。” “怎么了客们?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,133評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵崇决,是天一觀的道長(zhǎng)材诽。 經(jīng)常有香客問(wèn)我,道長(zhǎng)恒傻,這世上最難降的妖魔是什么脸侥? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,532評(píng)論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮碌冶,結(jié)果婚禮上湿痢,老公的妹妹穿的比我還像新娘。我一直安慰自己扑庞,他們只是感情好譬重,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,585評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著罐氨,像睡著了一般臀规。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上栅隐,一...
    開(kāi)封第一講書(shū)人閱讀 51,462評(píng)論 1 302
  • 那天塔嬉,我揣著相機(jī)與錄音,去河邊找鬼租悄。 笑死谨究,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的泣棋。 我是一名探鬼主播胶哲,決...
    沈念sama閱讀 40,262評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼潭辈!你這毒婦竟也來(lái)了鸯屿?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,153評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤把敢,失蹤者是張志新(化名)和其女友劉穎寄摆,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體修赞,經(jīng)...
    沈念sama閱讀 45,587評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡婶恼,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,792評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了榔组。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片熙尉。...
    茶點(diǎn)故事閱讀 39,919評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖搓扯,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情包归,我是刑警寧澤锨推,帶...
    沈念sama閱讀 35,635評(píng)論 5 345
  • 正文 年R本政府宣布,位于F島的核電站,受9級(jí)特大地震影響换可,放射性物質(zhì)發(fā)生泄漏椎椰。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,237評(píng)論 3 329
  • 文/蒙蒙 一沾鳄、第九天 我趴在偏房一處隱蔽的房頂上張望慨飘。 院中可真熱鬧,春花似錦译荞、人聲如沸瓤的。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,855評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)圈膏。三九已至,卻和暖如春篙骡,著一層夾襖步出監(jiān)牢的瞬間稽坤,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,983評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工糯俗, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留尿褪,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,048評(píng)論 3 370
  • 正文 我出身青樓得湘,卻偏偏與公主長(zhǎng)得像杖玲,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子忽刽,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,864評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容