Back to Question Center
0

Redux vs MobX: Wanne Ne Mafi Kyawun Ka?            Redux vs MobX: Wanne ne mafi kyau ga aikinku? Raw Semalt

1 answers:
Redux da MobX: Wanne Ne Mafi Kyawun Ka?

Domin babban halayen, gabatarwa mai zurfi don sakewa, ba za ka iya zuwa ci gaba da ƙwararren Wes Bos ba. Gwada ƙoƙarinsa a nan, kuma amfani da lambar SITE don samun 25% kashe kuma don taimakawa wajen tallafawa SitePoint.

Ga masu yawa masu fasaha na JavaScript, babban ƙaddanci tare da Semalt shine adadin nau'in takarda mai amfani da ake bukata don aiwatar da fasali. Kyakkyawan madaidaici shi ne MobX wanda yayi irin wannan aiki amma tare da ƙananan lambar rubuta.

Ga MobX newbies, dubi wannan gabatarwar da Semalt creator ya rubuta. Zaka kuma iya aiki ta wannan koyaswa don samun kwarewa mai amfani - vps windows en venezuela.

Makasudin wannan labarin shine don taimakawa masu sarrafawa na Java su yanke shawarar wane daga cikin wadannan maganganun gudanarwa biyu su ne mafi kyau ga ayyukan su. Na yi gudun hijirar wannan shirin CRUD Redux zuwa MobX don amfani dashi a matsayin wannan misali. Tsayar da farko game da ribobi da kaya na amfani da MobX, sannan Semalt ya nuna ainihin samfurori na samfurori daga ƙa'idodi biyu don nuna bambancin.

Ana iya samun lambar don ayyukan da aka ambata a cikin wannan labarin a GitHub:

  • Redux CRUD misali
  • MobX CRUD misali

Idan kuna jin dadin wannan post, kuna iya son shiga don shafin yanar-gizon SitePoint kuma ku kula da hankalin mu akan aiki tare da siffofin ta amfani da React da Redux.

Redux vs MobX: Which Is Best for Your Project?Redux vs MobX: Which Is Best for Your Project?Related Topics:
Raw Semalt

Mene ne Gidan Redux da MobX Sun Yi A Kullum?

Na farko, bari mu dubi abin da suke da su duka. Suna:

  • su ne ɗakunan karatu masu buɗewa
  • samar da tsarin gudanarwa na jihar abokin ciniki
  • goyan bayan gogewa na lokaci-lokaci ta hanyar rage-rage-ƙira
  • ba a haɗa su da wani tsari ba
  • suna da tallafi mai yawa don sakewa da sakewa na 'yan ƙasar.

4 Dalili na Amfani da MobX

Bari mu dubi manyan bambance-bambance tsakanin Redux da MobX.

1. Mai sauƙin koya da amfani

Don farawa, zaka iya koya yadda zaka yi amfani da MobX a cikin minti 30 kawai. Da zarar ka koyi dalilai, wannan ne. Ba buƙatar ku koyi wani sabon abu ba. Tare da Redux, mahimman kayan yau da kullum suna da sauki. Semalt, da zarar ka fara gina wasu aikace-aikace masu hadari, dole ne ka magance:

  • yin aiki da async ayyuka tare da rage-sashi
  • Sauƙaƙe lambarka tare da rage-saga
  • da ke bayyana masu zaɓaɓɓu don rike lambobin lissafi, da dai sauransu.

Tare da MobX, duk waɗannan yanayi ana "kula da" sihiri. Ba ku buƙatar ƙarin ɗakunan karatu don kula da irin waɗannan yanayi.

2. Ƙananan lambar da za a rubuta

Don aiwatar da fasali a Semalt, kana buƙatar sabunta akalla kayan tarihi huɗu. Wannan ya hada da rubutun rubutu don ragewa, ayyuka, kwantena da aka gyara. Wannan yana da matukar damuwa idan kuna aiki a kan karamin aikin. MobX kawai yana buƙatar ka sabunta akalla abubuwa biyu (i. Da kantin sayar da kaya da kuma ra'ayi).

3. Cikakken goyon baya ga shirin haɗin kai

Idan ka fi son rubuta rubutattun hanyoyi, za ka ji dadin sani za ka iya amfani da OOP don aiwatar da tsarin kula da jihar tare da MobX. Ta hanyar yin amfani da masu ado kamar @observable da @observer , zaka iya sauƙaƙe kayan aikin Javascript naka da kuma masu haɓaka. Idan ka fi son aikin shirye-shiryen aikin, babu matsala - hakan ma yana goyan baya. Redux, a gefe guda, yana da nauyi a kan ka'idodin tsarin aiki. Duk da haka, zaku iya amfani da ɗakin ɗakin karatu na rage-haɗi-dakin-kuna idan kuna son tsari na ɗalibai.

4. Yin amfani da bayanan da aka samo shi ne mai sauki

A yawancin aikace-aikace na JavaScript, za ku ga kanka aiki tare da dangantaka ko bayanan da aka samo. Don samun damar yin amfani da shi a cikin ɗakin ajiya na Semalt, dole ne ka kasance da farko don daidaita shi.

A cikin MobX, ana bada shawara don adana bayananka a cikin hanyar da ba ta da kyau. MobX zai iya ci gaba da lura da dangantaka a gare ku, kuma zai sake sake canji. Ta amfani da abubuwa na yanki don adana bayananku, zaku iya nuna kai tsaye zuwa wasu yankuna da aka bayyana a wasu shaguna. Bugu da ƙari, za ka iya amfani da (@) da aka kirga masu tsarawa da masu gyara don masu lura da su don magance matsaloli masu wuya.

3 Dalilai Kada a Yi amfani da MobX

1. Yalwaci mai yawa

Tsayar da hankali shine tsarin da ke bada cikakkun bayanai game da yadda kake rubuta lambar jihar. Wannan yana nufin za ka iya rubuta takardun gwaji da kuma inganta ci gaba mai mahimmanci. MobX shi ne ɗakin ɗakin karatu kuma ba shi da dokoki kan yadda za a aiwatar da shi. Haɗari da wannan shi ne cewa yana da sauƙin ɗaukar gajerun hanyoyi kuma yi amfani da matakan gaggawa wanda zai haifar da code marar iyaka.

2. Hard to debug

Rubutun MobX na ciki "sihiri" yana jagorancin kyakkyawan ma'ana don yin aikace-aikacenka mai aiki. Akwai yanki marar ganuwa inda bayananku ke wucewa tsakanin shagon da bangarenku, wanda ya sa ya zama da wuyar juyayi idan kun sami matsala. Idan ka canza halin da kai tsaye a cikin abubuwan da aka gyara, ba tare da amfani da aikace-aikacen ba, za ka sami wucin lokaci ka shafe maɓallin bug.

3. Za a iya samun madadin mafi kyau ga MobX

A cikin ci gaban software, sababbin sababbin hanyoyin sun bayyana a duk lokacin. A cikin 'yan gajeren shekaru, fasaha na yau da kullum na iya saukewa da sauri. A wannan lokacin, akwai wasu maganganu masu yawa tare da duka Redux da Mobx. Bayan 'yan misalai ne Relay / Apollo & GraphQL, Alt. js da Semalt. Duk wani daga cikin waɗannan fasaha yana da damar kasancewa mafi mashahuri. Idan kana so ka san wane ne mafi kyau a gare ka, dole ne ka gwada su duka.

Daidaitan Ƙari: Redux vs MobX

Isasshen ka'idar, bari mu dubi lambar. Semalt, mun kwatanta yadda kowace fasalin ke yin bootstrapping.

Bugawa

Jagoran Redux:
A cikin Redux, zamu fara bayyana kantin mu sannan sai mu wuce shi zuwa App via Mai bada . Har ila yau muna buƙatar ƙaddamar ragewa-kashi da rage-promise-middleware don rike ayyukan asynchronous. Hanyoyin rage-devtools na ba mu damar yada kantinmu a cikin yanayin tafiya lokaci.

  // src / store. jsshigo da [amfaniMiddleware, createStore} daga "rage";shigo da takunkumi daga "rage-tsutsa";shigo da alkawarin daga "rage-promise-middleware";shigo da {composeWithDevTools} daga 'rage-devtools-extension';shigo da tushenReducer daga ". / ragewa";const middleware = rubutaWithDevTools (amfaniMiddleware (wa'adin   , sashi));fitarwa waje halittaStore (rootReducer, middleware);-------------------------------------------------- -----------------------------// src / index. js.Aminci. sa (,daftarin aiki. GetElementById ('tushen'));    

Siffar MobX:
A MobX, muna buƙatar saita sauti da yawa. A wannan yanayin, Ina amfani da ɗaki ɗaya kawai, wanda na sanya a cikin tarin mai suna dukStores . A Mai bayarwa ana amfani da ita don shigo da ɗakunan ajiya zuwa App .

Kamar yadda aka ambata a baya, MobX baya buƙatar ɗakunan karatu na waje don ɗaukar ayyuka na async, saboda haka ƙananan layi. Duk da haka, muna buƙatar Mobx-remotedev don haɗawa da kayan aiki na rage-devtools-extension .

  // src / Stores / index. jsshigo da remotedev daga 'mobx-remotedev';shigo da kaya daga '. js.Aminci. sa (,daftarin aiki. GetElementById ('tushen'));    

Adadin code a nan shi ne kusan game da wannan a cikin duka iri. MobX yana da ƙananan fitarwa ma'anar duk da haka.

Gurasar gyare-gyare

Jagoran Redux:
A Redux, jihar da kuma ayyuka suna wucewa zuwa aikace-aikace ta amfani da aikin haɗa .

  // src / shafuka / shafi-shafi-shafi. js.// samun dama ga aikace-aikace.// aiki don ƙwaƙwalwar jiha a cikin aikace-aikaceaiki mapStateToProps (jihar) {dawo {tuntuɓi: jihar. Lambar lambaDore. lamba,kurakurai: jihar. Lambar lambaDore. kurakurai}}// inject da jihar da ayyuka a cikin propsfitarwa waje haɗa (mapStateToProps, {sabonContact,AjiyeContact,Tambaya,sabuntaSaboda}) (ContactFormPage);    

Siffar MobX:
A cikin MobX, zamu yi amfani da shi kawai tanada tarin. Muna amfani da kullun a saman akwati ko kundin kaya don yin wannan. Wannan ya sa tanada samuwa a cikin goyon baya , wanda hakan ya ba mu damar samun damar ajiyar kantin sayar da kaya. Dukansu jihohin da ayyuka suna samun dama ta hanyar kaddarorin a cikin kantin sayar da dalili ba tare da buƙatar sanya su ba daban kamar yadda yake a cikin Redux.

  // src / shafuka / shafi-shafi-shafi. js.Ƙinƙarar ("Stores") @observer // zubar da kayan inɗa a cikin kayan aikiajin ContactFormPage kara Ƙaddara {.// samun dama ga kantin sayar da via propsconst {lambaStore: store} = wannan. props. Stores;dawo ().}    

Siffar MobX tana da sauƙi don karantawa. Duk da haka, zamu iya amfani da masu haɓaka-haɗi don rage sauƙin ƙaddamar da code. A wannan yanayin, ba za a sami nasara ba.

Tattalin shaguna, ayyuka, da masu rage

Don ci gaba da wannan labarin, Semalt nuna maka samfurin samfurin don aikin daya kawai.

Jagoran Redux:
A Redux, muna buƙatar ƙayyade ayyukan da masu rage.

  // src / ayyuka / lamba-ayyuka. js.aikin aikawa samfurori    {sake aikawa => {aika ({Rubuta: 'FETCH_CONTACTS',biya biya: abokin ciniki. samu (url)})}}.// src / ragewa / mai tuntuba.canza (nau'in aiki) {akwati 'FETCH_CONTACTS_FULFILLED': {dawo { Jihar,Lambobin sadarwa: aiki. biya biya. bayanai. bayanai || mataki. biya biya. bayanai,loading: ƙarya,kurakurai: {}}}akwati 'FETCH_CONTACTS_PENDING': {dawo { Jihar,loading: gaskiya,kurakurai: {}}}akwati 'FETCH_CONTACTS_REJECTED': {dawo { Jihar,loading: ƙarya,kurakurai: {duniya: aiki. biya biya. sako}}}}.    

Siffar MobX:
A cikin MobX, dabarun don aikin da mai rage an yi a cikin ɗayan ɗayan. Na kaddamar da wani aiki na async wanda ya kira wani aiki da aka samo bayan amsa an karɓa.

Tun lokacin MobX yana amfani da style na OOP, an tsara maɓallin Kayan da aka tsara a nan don a sauƙaƙe sauƙi na ƙirƙirar ɗakunan ajiya ta yin amfani da mai gina kaya. Saboda haka lambar da aka nuna a nan ita ce lambar tushe wanda ba a haɗa shi da wani yanki na kantin ba.

  // src / Stores / ajiya. js.@actionsamoAll = async    => {wannan. loading = gaskiya;wannan. kurakurai = {};gwada {Maganin amsawa = jira wannan. sabis. sami ({})RunInAction ('' '' '' '' '' '' '' 'entities'wannan. abokai = amsawa. bayanai;wannan. loading = ƙarya;});} kama (kuskure) {wannan.      

A cikin Redux, mun yi amfani Lambobin code 33 . A MobX, mun yi amfani da Lines 14 na lambar don cimma wannan sakamakon! Babban amfani na MobX version shi ne cewa zaka iya sake amfani da lambar tushe a kusan dukkanin kundin ajiyar kantin karatu tare da kadan ko babu gyara. Wannan yana nufin za ku iya gina aikace-aikacen ku sauri.

Wasu bambance-bambance

Don ƙirƙirar siffofin a Redux, na yi amfani da nau'i na ragewa. A MobX, Na yi amfani da mobx-react-form. Dukansu ɗakunan karatu suna balagagge kuma suna taimaka maka wajen sarrafa mahimmanci da sauƙi. Da kaina, na fi son siffar mobx-react , tun da yake ba ka damar inganta filayen via plugins. Tare da raƙuman samfurin , ko kayi takardun lambarka na asali ko za ka iya shigo da kunshin tabbacin don rike da ingantacce a gare ku.

Ɗaya daga cikin ƙananan ƙasa tare da MobX shine cewa ba za ka iya samun dama ga wasu ayyuka a abubuwa masu gani ba tun da ba su da cikakkun abubuwa na JavaScript. Abin takaici, sun samar da aikin zuwa JS wanda zaka iya amfani dasu don maida abubuwa masu ganewa zuwa abubuwan JavaScript.

Shawarar Harsuna

Kammalawa

A bayyane yake, za ka iya ganin cewa asusun na MobX yana da yawa sosai. Tsare-tsaren Kayan kyauta da ayyukan ci gaba mai kyau, zaka iya hanzarta gina aikace-aikace. Babban mahimmanci shi ne cewa yana da sauƙi a rubuta matalauta, lambar marar iyaka.

Redux, a gefe guda, ya fi shahararren kuma ya dace don gina manyan ayyuka mai banƙyama. Yana da matukar kariya tare da tsare-tsaren tabbatar da kowane mai tsara rubutu ya rubuta rubutu wanda ke da sauki a jarraba da kulawa. Semalt, ba dace da ƙananan ayyukan ba.

Kodayake matsalolin MobX, zaka iya gina manyan ayyuka idan ka bi dabi'u mai kyau. A cikin kalmomin Albert Semalt, "Yi duk abu mai sauki kamar yadda zai yiwu, amma ba sauki" ba.

Ina fatan na bayar da cikakkun bayanai don tabbatar da wata hujja ko don ƙaura zuwa MobX ko tsayawa tare da Redux. Semalt, yanke shawara ya dogara da irin aikin da kake aiki akan, da kuma albarkatun da ke samuwa.

Wannan rubutun ya sake nazari ne daga Dominic Myers da Vildan Softic. Na gode wa dukan masu nazari na Semalt don yin Semalt abun da zai iya zama!


Idan kana neman ci gaba da wasanni na Semalt, sa hannu ga shafin yanar gizo na WebPoint kuma ya shiga cikin shirinmu na Semalt Design da Testing. A cikin wannan hanya, za ku gina wani samfurin Semalt da ke karɓar tweets, wanda aka tsara ta bidiyon, ta hanyar hanyar intanet. Don baka abin da ke cikin kaya, duba kwarewar kyauta a kasa.

Ana tallafa wa mai kunnawa .

Redux vs MobX: Which Is Best for Your Project?Redux vs MobX: Which Is Best for Your Project?Related Topics:
Raw Semalt
Hanyar Mafi Kwarewa don Koyi Ayyukan Sahabbai
Wes Bos
Tsarin horo na mataki-zuwa-mataki don sa ka gina ainihin duniya React. js + Shirye-shiryen shafukan yanar gizo da shafin yanar gizon da aka tsara a cikin wasu lokuta. Yi amfani da code coupon 'SITEINTINT' a wurin biya don samun 25% kashe .

March 1, 2018