-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/v0.0.2 #3
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
Open
kolyasya
wants to merge
27
commits into
main
Choose a base branch
from
feature/v0.0.2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
5ef5d32
feat: Add example and Meteor v.3 support, add types
kolyasya 60e2648
feat: Move code to ./src before publish
kolyasya 0a3bad4
feat: Update code, add logging and params, update docs
kolyasya 7657b0c
feat: Adjust pre-publish
kolyasya 3e57d4a
fix: Update gitignore
kolyasya 7010cf8
fix: Update docs
kolyasya 6b4a0a2
feat: Add ability to override params during call
kolyasya 5e8482b
feat: Add ability to override params call, adjust types
kolyasya d221b2e
fix: Adjust package version
kolyasya 215f845
feat: Add ability to validate params
eadenink dc8dd41
feat: Update params passing
eadenink 1e746b3
feat: Update package in example
eadenink 390a84e
fix: Default validate function
eadenink 8627183
feat: Update example for the new params passing
eadenink 07f3319
feat: Update Meteor
kolyasya 16eb9b1
feat: Implement separate function to transform params
eadenink 5a0bd9e
fix: Adjust validation error message
kolyasya 9af5999
Merge pull request #1 from kolyasya/feature/add-ability-to-validate-p…
kolyasya 6279b91
fix: Version Up
kolyasya 4a59459
feat: Prepare new version
kolyasya 5b77fb8
feat: Add transform example to readme
eadenink 50efc13
feat: Fix types approach
kolyasya 45d7d27
feat: Update types approach again
kolyasya b3344c8
fix: Optimize state initialization in useMeteorCall
Bboyredstar 5c03c51
Merge pull request #2 from Bboyredstar/patch-1
kolyasya 40958d4
fix: Make sure we run callback in case of error
kolyasya 36ecec6
fix: Make sure we stop loading on error
kolyasya 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .DS_Store |
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| node_modules/ |
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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # This file contains information which helps Meteor properly upgrade your | ||
| # app when you run 'meteor update'. You should check it into version control | ||
| # with your project. | ||
|
|
||
| notices-for-0.9.0 | ||
| notices-for-0.9.1 | ||
| 0.9.4-platform-file | ||
| notices-for-facebook-graph-api-2 | ||
| 1.2.0-standard-minifiers-package | ||
| 1.2.0-meteor-platform-split | ||
| 1.2.0-cordova-changes | ||
| 1.2.0-breaking-changes | ||
| 1.3.0-split-minifiers-package | ||
| 1.4.0-remove-old-dev-bundle-link | ||
| 1.4.1-add-shell-server-package | ||
| 1.4.3-split-account-service-packages | ||
| 1.5-add-dynamic-import-package | ||
| 1.7-split-underscore-from-meteor-base | ||
| 1.8.3-split-jquery-from-blaze |
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| local |
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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # This file contains a token that is unique to your project. | ||
| # Check it into your repository along with the rest of this directory. | ||
| # It can be used for purposes such as: | ||
| # - ensuring you don't accidentally deploy one app on top of another | ||
| # - providing package authors with aggregated statistics | ||
|
|
||
| mwteyo9y63m.nsvo9ukypcz7 |
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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Meteor packages used by this project, one per line. | ||
| # Check this file (and the other files in this directory) into your repository. | ||
| # | ||
| # 'meteor add' and 'meteor remove' will edit this file for you, | ||
| # but you can also edit it by hand. | ||
|
|
||
| meteor-base@1.5.1 # Packages every Meteor app needs to have | ||
| mobile-experience@1.1.1 # Packages for a great mobile UX | ||
| mongo@1.16.10 # The database Meteor supports right now | ||
| reactive-var@1.0.12 # Reactive variable for tracker | ||
|
|
||
| standard-minifier-css@1.9.2 # CSS minifier run for production mode | ||
| standard-minifier-js@2.8.1 # JS minifier run for production mode | ||
| es5-shim@4.8.0 # ECMAScript 5 compatibility for older browsers | ||
| ecmascript@0.16.8 # Enable ECMAScript2015+ syntax in app code | ||
| typescript@4.9.5 # Enable TypeScript syntax in .ts and .tsx modules | ||
| shell-server@0.5.0 # Server-side component of the `meteor shell` command | ||
| hot-module-replacement@0.5.3 # Update client in development without reloading the page | ||
|
|
||
|
|
||
| static-html@1.3.2 # Define static page content in .html files | ||
| react-meteor-data # React higher-order component for reactively tracking Meteor data | ||
| zodern:types # Pull in type declarations from other Meteor packages |
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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| server | ||
| browser |
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| METEOR@2.16 |
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 |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| allow-deny@1.1.1 | ||
| autoupdate@1.8.0 | ||
| babel-compiler@7.10.5 | ||
| babel-runtime@1.5.1 | ||
| base64@1.0.12 | ||
| binary-heap@1.0.11 | ||
| blaze-tools@1.1.3 | ||
| boilerplate-generator@1.7.2 | ||
| caching-compiler@1.2.2 | ||
| caching-html-compiler@1.2.1 | ||
| callback-hook@1.5.1 | ||
| check@1.4.1 | ||
| ddp@1.4.1 | ||
| ddp-client@2.6.2 | ||
| ddp-common@1.4.1 | ||
| ddp-server@2.7.1 | ||
| diff-sequence@1.1.2 | ||
| dynamic-import@0.7.3 | ||
| ecmascript@0.16.8 | ||
| ecmascript-runtime@0.8.1 | ||
| ecmascript-runtime-client@0.12.1 | ||
| ecmascript-runtime-server@0.11.0 | ||
| ejson@1.1.3 | ||
| es5-shim@4.8.0 | ||
| fetch@0.1.4 | ||
| geojson-utils@1.0.11 | ||
| hot-code-push@1.0.4 | ||
| hot-module-replacement@0.5.3 | ||
| html-tools@1.1.3 | ||
| htmljs@1.1.1 | ||
| id-map@1.1.1 | ||
| inter-process-messaging@0.1.1 | ||
| launch-screen@2.0.0 | ||
| logging@1.3.4 | ||
| meteor@1.11.5 | ||
| meteor-base@1.5.1 | ||
| minifier-css@1.6.4 | ||
| minifier-js@2.8.0 | ||
| minimongo@1.9.4 | ||
| mobile-experience@1.1.1 | ||
| mobile-status-bar@1.1.0 | ||
| modern-browsers@0.1.10 | ||
| modules@0.20.0 | ||
| modules-runtime@0.13.1 | ||
| modules-runtime-hot@0.14.2 | ||
| mongo@1.16.10 | ||
| mongo-decimal@0.1.3 | ||
| mongo-dev-server@1.1.0 | ||
| mongo-id@1.0.8 | ||
| npm-mongo@4.17.2 | ||
| ordered-dict@1.1.0 | ||
| promise@0.12.2 | ||
| random@1.2.1 | ||
| react-fast-refresh@0.2.8 | ||
| react-meteor-data@2.7.2 | ||
| reactive-var@1.0.12 | ||
| reload@1.3.1 | ||
| retry@1.1.0 | ||
| routepolicy@1.1.1 | ||
| shell-server@0.5.0 | ||
| socket-stream-client@0.5.2 | ||
| spacebars-compiler@1.3.1 | ||
| standard-minifier-css@1.9.2 | ||
| standard-minifier-js@2.8.1 | ||
| static-html@1.3.2 | ||
| templating-tools@1.2.2 | ||
| tracker@1.3.3 | ||
| typescript@4.9.5 | ||
| underscore@1.6.1 | ||
| webapp@1.13.8 | ||
| webapp-hashing@1.1.1 | ||
| zodern:types@1.0.13 |
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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| body { | ||
| padding: 10px; | ||
| font-family: sans-serif; | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <head> | ||
| <title>example</title> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div id="react-target"></div> | ||
| </body> |
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 |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import React from 'react'; | ||
| import { createRoot } from 'react-dom/client'; | ||
| import { Meteor } from 'meteor/meteor'; | ||
| import { App } from '/imports/ui/App'; | ||
|
|
||
| Meteor.startup(() => { | ||
| const container = document.getElementById('react-target'); | ||
| const root = createRoot(container!); | ||
| root.render(<App />); | ||
| }); |
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 |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { Mongo } from 'meteor/mongo'; | ||
|
|
||
| export interface Link { | ||
| _id?: string; | ||
| title: string; | ||
| url: string; | ||
| createdAt: Date; | ||
| } | ||
|
|
||
| export const LinksCollection = new Mongo.Collection<Link>('links'); |
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 |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import React, { useEffect } from 'react'; | ||
|
|
||
| import { useMeteorCall } from './react-meteor-method-hooks/useMeteorCall'; | ||
|
|
||
| export const App = () => { | ||
| const [ | ||
| methodWithResult, | ||
| methodWithResultLoading, | ||
| methodWithResultError, | ||
| methodWithResultResult, | ||
| ] = useMeteorCall( | ||
| 'methodWithResult', | ||
| { | ||
| cb: (error, result) => { | ||
| console.log('methodWithResult callback', { error, result }); | ||
| }, | ||
| validate: (...params) => | ||
| params.every((param) => typeof param === 'string'), | ||
| transform: (...params) => params.map((p, i) => `${i + 1}-${p}`), | ||
| forceSyncCall: false, | ||
| logging: false, | ||
| suppressErrorLogging: false, | ||
| }, | ||
| 'one', | ||
| 'two', | ||
| 'three' | ||
| ); | ||
|
|
||
| const [ | ||
| methodWithError, | ||
| methodWithErrorLoading, | ||
| methodWithErrorError, | ||
| methodWithErrorResult, | ||
| ] = useMeteorCall('methodWithError', { | ||
| cb: (error, result) => { | ||
| console.log('methodWithError callback', { error, result }); | ||
| }, | ||
| forceSyncCall: false, | ||
| logging: true, | ||
| suppressErrorLogging: false, | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| methodWithResult(); | ||
| methodWithError(); | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| const timeout = setTimeout(() => { | ||
| // methodWithResult('one', 'two', 'three'); | ||
| // methodWithResult(); | ||
| // methodWithResult({}); | ||
| methodWithResult({ customParam: true }); | ||
| }, 15000); | ||
|
|
||
| return () => clearTimeout(timeout); | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| console.log({ | ||
| methodWithResultLoading, | ||
| methodWithResultError, | ||
| methodWithResultResult, | ||
| methodWithErrorLoading, | ||
| methodWithErrorError, | ||
| methodWithErrorResult, | ||
| }); | ||
| }, [ | ||
| methodWithResultLoading, | ||
| methodWithResultError, | ||
| methodWithResultResult, | ||
| methodWithErrorLoading, | ||
| methodWithErrorError, | ||
| methodWithErrorResult, | ||
| ]); | ||
|
|
||
| return ( | ||
| <div style={{ display: 'flex' }}> | ||
| <div> | ||
| <h4>methodWithResult</h4> | ||
| <pre> | ||
| {JSON.stringify( | ||
| { | ||
| methodWithResultLoading, | ||
| methodWithResultError, | ||
| methodWithResultResult, | ||
| }, | ||
| undefined, | ||
| 2 | ||
| )} | ||
| </pre> | ||
| </div> | ||
| <div> | ||
| <h4>methodWithError</h4> | ||
| <pre> | ||
| {JSON.stringify( | ||
| { | ||
| methodWithErrorLoading, | ||
| methodWithErrorError, | ||
| methodWithErrorResult, | ||
| }, | ||
| undefined, | ||
| 2 | ||
| )} | ||
| </pre> | ||
| </div> | ||
| </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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| export type UseMeteorCallHookConfig = { | ||
| /** Callback to be executed after the method is called */ | ||
| cb?: (error: object | undefined, result: any) => void; | ||
|
|
||
| /** Validate params before handler execution */ | ||
| validate?: (...params: any[]) => boolean; | ||
| /** Transform params after validation before handler execution */ | ||
| transform?: (...params: any[]) => any[]; | ||
|
|
||
| /** Forces to use Meteor.call() instead of Meteor.callAsync() */ | ||
| forceSyncCall?: boolean; | ||
| /** Adds some logging in console */ | ||
| logging?: boolean; | ||
| /** | ||
| * By default the package logs console.error for all incoming errors | ||
| * The setting disables such logs | ||
| */ | ||
| suppressErrorLogging?: boolean; | ||
| }; | ||
|
|
||
| export type UseMeteorCallHookResult = [ | ||
| methodHandler: (...params: any[]) => Promise<any>, | ||
| loading: boolean, | ||
| error: object | undefined, | ||
| result: any | ||
| ]; | ||
|
|
||
| export type UseMeteorCallHookState = { | ||
| loading: boolean; | ||
| error?: object; | ||
| result: any; | ||
| }; | ||
|
|
||
| export function useMeteorCall( | ||
| methodName: string, | ||
| meteorCallHookConfig?: UseMeteorCallHookConfig, | ||
| ...methodParams: any[] | ||
| ): UseMeteorCallHookResult; |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file contains commented-out code. If this code is no longer needed, it should be removed to improve code clarity and maintainability. If it's for demonstration, it would be better to explain its purpose in a comment rather than leaving dangling code.