New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dittolive/ditto

Package Overview
Dependencies
Maintainers
0
Versions
615
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dittolive/ditto

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

  • 4.9.4
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
710
decreased by-19.13%
Maintainers
0
Weekly downloads
 
Created
Source

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.4

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.

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

Copyright © 2023 DittoLive Incorporated. All rights reserved.

Keywords

FAQs

Package last updated on 17 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc