-
Notifications
You must be signed in to change notification settings - Fork 167
[WIP] New hooks #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
[WIP] New hooks #298
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
d8ad782
Use React.DependencyList instead of Array<any>
CaptainN c4c9f62
Add an accounts hook package
CaptainN b1281d1
Add react-meteor-state hook package
CaptainN 5932980
Add react-mongo slim hooks package
CaptainN 7460169
Always render on commit and apply feedback on deps
CaptainN 0b99ffe
Fix subscriptions not closed when stopping computation
rijk d94b254
Merge pull request #302 from rijk/new-hooks
CaptainN 98d80d2
Voidable sub factory, reactive ready, and a Readme
CaptainN b9404da
Use factoryless useSubscription other improvements
CaptainN e075fba
Help Typescript keep track of type of refs
CaptainN 0d9f3ba
Fix ready() doesn't update, and update react-mongo type def
CaptainN e11f8bc
Remove unneeded complexity in useSubscription
CaptainN d5b5f8e
Use memoized refs.params to reduce useEffect churn
CaptainN f59dd39
Make useCursor memoize fetch results
CaptainN ba67ebb
First run after deps change returns the right data
CaptainN 37ff546
Fix initial data after deps change behavior
CaptainN 783dad9
Add useFind, useFindOne, useCount
CaptainN 9aec19d
Make useFindOne and useCount accept factory methods
CaptainN 754953a
Update useTracker cleaner impl, and clean up tests
CaptainN 9fa3df9
Apply feedback to useFind and useSubscription
CaptainN 9ed323f
Check for cursor on server too
CaptainN 9dabef9
Clean up type notation, pass comp to reactiveFn
CaptainN b06c4cd
Fix failing resubscribe tests by forcing full flush cylce
CaptainN 6d056ec
Improve signal to noice of resubscribe tests
CaptainN 51b2f38
Update packages and add typescript gen script
CaptainN File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,44 @@ | ||
meteor/react-mongo | ||
================== | ||
|
||
``` | ||
meteor add meteor/react-mongo | ||
``` | ||
|
||
A set of hooks for using Meteor's Mini Mongo Collections and pub/sub. | ||
|
||
There are two hooks | ||
|
||
| Hook | Function | ||
| ---- | -------- | ||
| useSubscription | Used to set up a Meteor subscription. In SSR, this hook is responsible for capturing data to be sent to the client for hydration. | ||
| useCursor | Manages the lifecycle of a Mongo Cursor | ||
|
||
Both methods accept a factory method, and deps. | ||
|
||
## useSubscription(factory, deps) | ||
|
||
`useSubscription` takes a factory method, which should return a subscription handle, and a deps array. It can also return `void` to conditionally set up no subscription. The hook returns a subscription handle with a reactive `ready` method. | ||
|
||
Invoking the `ready()` handle method will cause the hook to update react when the subscription becomes available. | ||
|
||
### Example | ||
|
||
```jsx | ||
import React from 'react' | ||
import { useSubscription } from 'meteor/react-mongo' | ||
|
||
const MyComponent = ({ id = null }) => { | ||
const subscription = useSubscription(() => { | ||
if (id) return Meteor.subscribe(id) | ||
}, [id]) | ||
|
||
return <div> | ||
{ | ||
subscription.ready() | ||
? 'content ready' | ||
: 'loading...' | ||
} | ||
</div> | ||
} | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import { Meteor } from 'meteor/meteor'; | ||
import { Mongo } from 'meteor/mongo'; | ||
import { DependencyList } from 'react'; | ||
export declare const useSubscription: (factory: () => Meteor.SubscriptionHandle, deps?: DependencyList) => Meteor.SubscriptionHandle; | ||
declare type UseSubscriptionOptions = { | ||
deps?: DependencyList; | ||
updateOnReady?: boolean; | ||
}; | ||
export declare const useSubscription: (factory: () => Meteor.SubscriptionHandle | void, deps?: DependencyList | UseSubscriptionOptions) => void; | ||
CaptainN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export declare const useCursor: <T = any>(factory: () => Mongo.Cursor<T>, deps?: DependencyList) => Mongo.Cursor<T>; | ||
export {}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.