Skip to content

vermiculite/meteorjs-client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

346 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

meteorjs-client

meteorjs-client npm version Dependency Status

Install

yarn add meteorjs-client

or

npm i --save meteorjs-client

Usage

Connecting to the server

Should be done only once.

Secure connection

Use the wss protocol for connecting to secure deployments with ssl.

Meteor.connect('wss://example.com:3000/websocket')

Insecure connection

Use the ws protocol for insecure connections, e.g. during development.

Meteor.connect('192.168.1.23')

Disconnecting

Meteor.disconnect()

Data fetching

import Meteor, {withTracker} from 'meteorjs-client'

import  SomeComponent from './SomeComponent'

function trackerFunction({listId}) {
  const stuffHandle = Meteor.subscribe('stuffInList', listId)
  const listHandle = Meteor.subscribe('aList', listId)
  const stuff = Meteor.collection('stuff').find({listId})
  const list = Meteor.collection('list').findOne(listId)
  return {
    listReady: listHandle.ready(),
    list,
    stuffReady: stuffHandle.ready(),
    stuff,
  }
}

export default withTracker(trackerFunction)(SomeComponent)

Here SomeComponent will receive stuffReady and stuff props. Unlike standard Meteor there is no need to call fetch as find returns an array.

Calling server side methods

import {show} from './my-popup-alerts'

Meteor.call('arrive', function(err) {
    if (err) {
      show('Error clocking in')
    }
  })

Meteor Accounts

Log in

Meteor.loginWithPassword(username, password, (err) => {
        this.setState({loggingIn: false})
        if (err) {
          this.setState({loginError: true})
        }
      })

Who is logged in?

const user = Meteor.user()
const userId = Meteor.userId()
console.log(`User is ${user ? user.username : 'Not logged in'}`)
const loggedIn = !!userId
const authToken = Meteor.getAuthToken()

Are we logging in?

Easily check if we are logging in.

const loggingIn = Meteor.loggingIn()

Server status

Are we currently connected to the server.

const {connected, status} = Meteor.status()

Why does this exist?

I have used react-native-meteor for some years in production. However, it is not being kept upto date and stopped me updating to newer react-native versions. This fork was created to stay up to date with changes in react, also reducing the size of the library removing non essential parts. This will aid the process of staying upto date.

Where is it going?

The idea is to have a core js library with implementations for React, Vue, React Native e.t.c. That's the plan lets see how we do

Want to help ?

Pull Requests and issues reported are welcome! :)

License

meteorjs-client is MIT Licensed.

About

Meteor Reactivity for your React Native application :)

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • JavaScript 100.0%