Gathering detailed insights and metrics for mobx-provide
Gathering detailed insights and metrics for mobx-provide
Gathering detailed insights and metrics for mobx-provide
Gathering detailed insights and metrics for mobx-provide
npm install mobx-provide
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
12 Stars
13 Commits
3 Watching
1 Branches
2 Contributors
Updated on 16 Jul 2020
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-41.7%
7
Compared to previous day
Last week
16.9%
90
Compared to previous week
Last month
21.3%
330
Compared to previous month
Last year
115.9%
2,170
Compared to previous year
MobX Store Provider Component Decorator
Do you like the convenience of importing store directly to your MobX component, but find testing a bit tricky? With mobx-provide
decorator, you can still retain your imports, pass the store as props through the decorator, and just prepend your store with props
or this.props
or use destructuring like const {store} = this.props
before the return statement in your render()
method.
The mobx-provide
is a decorator or higher-order component, that accepts a store object and a component as inputs, and returns a (enhanced) component.
npm install --save mobx-provide
1const store = {usersStore, articlesStore, adminStore} 2const ObserverComponentWithStore = provide(store)(observer(Component))
or
1const ObserverComponentWithStore = provide({ 2 usersStore, 3 articlesStore, 4 adminStore 5})(observer(Component))
1import React from 'react' 2import { observer } from 'mobx-react' 3import userProfile from 'stores/userProfile' 4 5export class UserProfile extends React.Component { 6 render () { 7 return ( 8 <div> 9 <h1>User Profile</h1> 10 <p>Name: {userProfile.name}</p> 11 <p>Email: {userProfile.email}</p> 12 </div> 13 ) 14 } 15} 16 17export default observer(UserProfile)
1import React from 'react' 2import { observer } from 'mobx-react' 3import userProfile from 'stores/userProfile' 4import provide from 'mobx-provide' 5 6export class UserProfile extends React.Component { 7 render () { 8 const {userProfile} = this.props 9 return ( 10 <div> 11 <h1>User Profile</h1> 12 <p>Name: {userProfile.name}</p> 13 <p>Email: {userProfile.email}</p> 14 </div> 15 ) 16 } 17} 18 19const ObserverComponent = observer(UserProfile) 20 21export default provide({userProfile})(ObserverComponent)
1+ const {userProfile} = this.props 2return ( 3 <div> 4 ... 5 </div> 6)
1- export default observer(UserProfile) 2+ const ObserverComponent = observer(UserProfile) 3+ export default provide({userProfile})(ObserverComponent)
There is not much difference between the two. You just have to reference the store using props:
const {userProfile} = this.props
Basically, you have to have two exports for your component, named export and default export. Your named export could be the plain component for your testing, and the default export for enhanced or observer component.
In your test file, import the plain component, create a new instance of your store and pass it as props as you normally would. Simple!
To contribute, please follow these steps:
npm install
git add -A
to add your changesnpm run commit
(Do not use git commit
)git push
Be the the next one to contribute! Add your name below:
MIT © Felipe Apostol
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/11 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More