All Projects → Gregivy → Simpleddp

Gregivy / Simpleddp

Licence: mit
An easy to use DDP client library

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Simpleddp

meteorman
A DDP client with GUI (The Postman for Meteor)
Stars: ✭ 51 (-60.77%)
Mutual labels:  meteor, apps
Ews Javascript Api
EWS API for TypeScript/JavaScript - ported from OfficeDev/ews-managed-api - node, cordova, meteor, Ionic, Electron, Outlook Add-Ins
Stars: ✭ 241 (+85.38%)
Mutual labels:  meteor, ionic
ionic4-angular8-crud-mobileapps-example
Ionic 4 Angular 8 Tutorial: Learn to Build CRUD Mobile Apps
Stars: ✭ 20 (-84.62%)
Mutual labels:  ionic, apps
pwa-theme-obliq
OBLIQ Progressive Web Application V2.0
Stars: ✭ 29 (-77.69%)
Mutual labels:  ionic, apps
ionic4-angular7-example
Ionic 4, Angular 7 and Cordova Tutorial: Build CRUD Mobile Apps
Stars: ✭ 57 (-56.15%)
Mutual labels:  ionic, apps
meteor-pg
Use PostgreSQL reactively in Meteor.
Stars: ✭ 24 (-81.54%)
Mutual labels:  reactive, meteor
Nativescript Ionic Template
📱 🖥 Create Mobile First apps, Web and Native sharing the code with Angular 🎉
Stars: ✭ 65 (-50%)
Mutual labels:  apps, ionic
Chihu2
ionic2-example <吃乎2>混合开发-美食app 🍜 ☕️ 🍦 (This is a support android and apple ionic2 case, a food app)
Stars: ✭ 124 (-4.62%)
Mutual labels:  ionic
Meteor Peerdb
Reactive database layer with references, generators, triggers, migrations, etc.
Stars: ✭ 128 (-1.54%)
Mutual labels:  meteor
Ionic4 Starter App Tutorial
Ionic 4 To Do List App. FREE Ionic 4 example app. Learn how to start using Ionic 4 to create a simple app with lists, forms and navigation.
Stars: ✭ 123 (-5.38%)
Mutual labels:  ionic
Vertx Auth
Stars: ✭ 122 (-6.15%)
Mutual labels:  reactive
Ionic Typescript Starter
📱 Platform and IDE agnostic starter project for building mobile apps with Ionic and TypeScript.
Stars: ✭ 124 (-4.62%)
Mutual labels:  ionic
Ayanami
🍭 A better way to react with state
Stars: ✭ 129 (-0.77%)
Mutual labels:  reactive
Meteor Reactive Publish
Reactive publish endpoints
Stars: ✭ 123 (-5.38%)
Mutual labels:  meteor
Influxdb Client Csharp
InfluxDB 2.0 C# Client
Stars: ✭ 130 (+0%)
Mutual labels:  reactive
Rapidoid
Rapidoid - Extremely Fast, Simple and Powerful Java Web Framework and HTTP Server!
Stars: ✭ 1,571 (+1108.46%)
Mutual labels:  reactive
Arkade
Open Source Kubernetes Marketplace
Stars: ✭ 2,343 (+1702.31%)
Mutual labels:  apps
Swiftdux
Predictable state management for SwiftUI applications.
Stars: ✭ 130 (+0%)
Mutual labels:  reactive
Callbag Basics
👜 Tiny and fast reactive/iterable programming library
Stars: ✭ 1,619 (+1145.38%)
Mutual labels:  reactive
Vectoriconsroundup
A comparison between popular vectorial icon fonts
Stars: ✭ 126 (-3.08%)
Mutual labels:  ionic

npm version Build Status Dependency Status devDependency Status

SimpleDDP 🥚

The aim of this library is to simplify the process of working with Meteor.js server over DDP protocol using external JS environments (like Node.js, Cordova, Ionic, ReactNative, etc).

It is battle tested 🏰 in production and ready to use 🔨.

If you like this project ⭐ is always welcome.

Important

SimpleDDP is written in ES6 and uses modern features like promises. Though its precompiled with Babel, your js environment must support ES6 features. So if you are planning to use SimpleDDP be sure that your js environment supports ES6 features or include polyfills yourself (like Babel Polyfill).

Project uses semantic versioning 2.0.0.

DDP (protocol) specification.

CHANGE LOG

Install

npm install simpleddp --save

Documentation

Plugins

Adding custom EJSON types

Example

First of all you need WebSocket implementation for your node app. We will use isomorphic-ws package for this since it works on the client and serverside.

npm install isomorphic-ws ws --save

Import/require simpleDDP.

const simpleDDP = require("simpleddp"); // nodejs
const ws = require("isomorphic-ws");

or

import simpleDDP from 'simpleDDP'; // ES6
import ws from 'isomorphic-ws';

Now you should make a new simpleDDP instance.

let opts = {
    endpoint: "ws://someserver.com/websocket",
    SocketConstructor: ws,
    reconnectInterval: 5000
};
const server = new simpleDDP(opts);

Connection is not going to be established immediately after you create a simpleDDP instance. If you need to check your connection simply use server.connected property which is true if you are connected to the server, otherwise it's false.

You can also add some events for connection status.

server.on('connected', () => {
    // do something
});

server.on('disconnected', () => {
    // for example show alert to user
});

server.on('error', (e) => {
    // global errors from server
});

As an alternative you can use a async/await style (or then(...)).

(async ()=>{
  await server.connect();
  // connection is ready here
})();

The next thing we are going to do is subscribing to some publications.

let userSub = server.subscribe("user_pub");
let otherSub = server.subscribe("other_pub",'param1',2); // you can specify arguments for subscription

(async ()=>{
  await userSub.ready();
  let nextSub = server.subscribe("next_pub"); // subscribing after userSub is ready
  await nextSub.ready();
  //all subs are ready here
})();

You can fetch all things you've subscribed for using server.collection method. Also you can get reactive data sources (plain js objects which will be automatically updated if something changes on the server).

(async ()=>{

  // call some method
  await server.call('somemethod');

  let userSub = server.subscribe("user",userId);
  await userSub.ready();

  // get non-reactive user object
  let user = server.collection('users').filter(user=>user.id==userId).fetch()[0];

  // get reactive user object
  let userReactiveCursor = server.collection('users').filter(user=>user.id==userId).reactive().one();
  let userReactiveObject = userReactiveCursor.data();

  // observing the changes
  server.collection('users').filter(user=>user.id==userId).onChange(({prev,next})=>{
    console.log('previus user data',state.prev);
    console.log('next user data',state.next);
  });

  // observing changes in reactive data source
  userReactiveCursor.onChange((newData)=>{
    console.log('new user state', newData);
  });

  let participantsSub = server.subscribe("participants");

  await participantsSub.ready();

  let reactiveCollection = server.collection('participants').reactive();

  // reactive reduce
  let reducedReactive = reactiveCollection.reduce((acc,val,i,arr)=>{
    if (i<arr.length-1)  {
      return acc + val.age;
    } else {
      return (acc + val.age)/arr.length;
    }
  },0);

  // reactive mean age of all participants
  let meanAge = reducedReactive.data();

  // observing changes in reactive data source
  userReactiveCursor.onChange((newData)=>{
    console.log('new user state', newData);
  });
})();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].