npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dittolive/ditto

v4.9.0

Published

Ditto is a cross-platform SDK that allows apps to sync with and even without internet connectivity.

Downloads

3,082

Readme

Ditto JS SDK

Ditto is a cross-platform SDK that allows mobile, web, and IoT apps to sync with and even without connectivity.

Version: 4.9.0

For more information please visit ditto.live, as well as the API Reference for this particular version.


Getting Started

Add the Ditto NPM package to your project:

npm install --save @dittolive/ditto

Import @dittolive/ditto in your source and start using it:

import { init, Ditto } from '@dittolive/ditto'

(async () => {
  // Initialize the Ditto module
  await init()

  // Create a Ditto context:
  const identity = { type: 'offlinePlayground', appID: 'live.ditto.playground' }
  const ditto = new Ditto(identity, 'playground')

  // Get hold of a collection:
  const cars = ditto.store.collection('cars')

  // Insert an entry:
  const fordBlack = { _id: 'ford-black-123', model: 'Ford', color: 'black' }
  await cars.upsert(fordBlack)

  // Find an entry by ID:
  const foundFordBlack = await cars.findByID('ford-black-123')
  console.log(foundFordBlack)

  // Remove an entry:
  await cars.findByID('ford-black-123').remove()

  // Done:
  console.log('Done, over and out.')
})()

Browser Environments

When running in the browser and other web environments, Ditto is powered by a WebAssembly core written in Rust. By default, Ditto will fetch the corresponding WebAssembly file from the web. That same file is contained within the NPM package under web/ditto.wasm so you can serve it yourself. Simply make the file accessible somewhere on your server and pass the URL to init():

import { init, Ditto } from '@dittolive/ditto'

(async () => {
  // Pass the URL to the ditto.wasm file:
  await init({ webAssemblyModule: 'https://my-app/assets/ditto.wasm' })

  // Then use Ditto as you normally would:
  const identity = { type: 'offlinePlayground', appID: 'live.ditto.playground' }
  const ditto = new Ditto(identity, 'playground')

  // ...
})()

This may be useful for development or production environments without a reliable internet connection. Make sure to properly configure the server to return the correct MIME type (application/wasm) and the Access-Control-Allow-Origin header if the .wasm file is served from a different domain. For production environments, make sure to use compression (gzip) and proper caching headers.

React Native Environments

Using Ditto in React Native requires configuration of the native iOS and Android projects to request network and location access permissions and to ensure compatibility with the target environment. Please refer to our guide for getting started with React Native for more information.

Playground

The NPM package has a built-in bare minimum playground web page (index.html) as well as a Node REPL ('playground.cjs') allowing you to start playing with the Ditto SDK right away. Simply cd into the package directory, run npm run play:web or npm run play:node and follow the on-screen instructions.

Copyright

Ditto JS SDK is a commercial product. Please consult LICENSE.md within this package for license details.

Copyright © 2023 DittoLive Incorporated. All rights reserved.