JSPM

syncity

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q22804F
  • License MIT

Syncity: A real-time, offline-first, plugin-based state synchronization framework

Package Exports

  • syncity
  • syncity/server.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (syncity) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Syncity 🚀

Next-Generation Real-Time State Synchronization & Offline-First Library

npm version License: MIT


Syncity is a cutting-edge JavaScript framework that empowers you to build modern, collaborative, and real-time web applications with ease. It offers seamless state synchronization, robust offline-first support, advanced conflict resolution, and a flexible, plugin-based architecture—all wrapped in a developer-friendly, event-driven API.


Table of Contents


Why Syncity? 🤔

  • Unified Experience: Manage client and server state seamlessly with one cohesive API.
  • Offline-First: Enjoy intelligent local caching and auto-queuing of updates so your app stays responsive even when offline.
  • Extensible & Future-Proof: Leverage our modular plugin system to add custom logging, analytics, or tailor conflict resolution strategies without altering core functionality.
  • Developer-Friendly: A minimal, event-driven API that integrates effortlessly with your favorite frameworks, reducing boilerplate code and accelerating development.

Key Features ✨

  • Real-Time Synchronization: Instantly propagate state changes across all connected clients using WebSockets.
  • Offline-First Capabilities: Robust local caching, update queuing, and service worker support ensure continuous operation even during network outages.
  • Advanced Conflict Resolution: Automatically merge concurrent updates using customizable strategies.
  • Modular Plugin Architecture: Extend core functionality easily with plugins for analytics, logging, or custom behaviors.
  • High Performance & Scalability: Optimized for low latency and high concurrency, making it perfect for demanding applications.

Use Cases 🚀

  • Collaborative Applications: Build live document editors, whiteboards, and real-time coding platforms.
  • Dynamic Dashboards: Create interactive dashboards for IoT data, financial feeds, or social media trends.
  • Multiplayer Games: Maintain synchronized game states with minimal latency across players.
  • Customer Support & Chat Systems: Develop responsive, real-time communication tools.

Installation ⚙️

Install Syncity via npm:

npm install syncity



Quick Start 🔥
Kickstart your project in just a few lines:



import SyncityClient from 'syncity-client';

// Initialize the client with your server URL
const syncity = new SyncityClient({ host: 'http://your-server.com' });

// Listen for the initial state
syncity.on('init', (state) => {
  console.log('Initial state:', state);
});

// Listen for state updates
syncity.on('stateUpdate', (state) => {
  console.log('Updated state:', state);
});

// Update the state (include a timestamp for conflict resolution)
syncity.updateState({ counter: 1, timestamp: Date.now() });


Framework Integrations 🛠️
React
Syncity Context Provider Example:


// SyncityProvider.js
import React, { createContext, useEffect, useState } from 'react';
import SyncityClient from 'syncity-client';

export const SyncityContext = createContext();

export function SyncityProvider({ children, host }) {
  const [state, setState] = useState({});
  const [syncity, setSyncity] = useState(null);

  useEffect(() => {
    const client = new SyncityClient({ host });
    setSyncity(client);
    client.on('init', setState);
    client.on('stateUpdate', setState);
    return () => client.disconnect();
  }, [host]);

  return (
    <SyncityContext.Provider value={{ state, syncity }}>
      {children}
    </SyncityContext.Provider>
  );
}
Example Component:


// Counter.js
import React, { useContext } from 'react';
import { SyncityContext } from './SyncityProvider';

function Counter() {
  const { state, syncity } = useContext(SyncityContext);

  const increment = () => {
    const newValue = (state.counter || 0) + 1;
    syncity.updateState({ counter: newValue, timestamp: Date.now() });
  };

  return (
    <div>
      <h2>Counter: {state.counter || 0}</h2>
      <button onClick={increment}>Increment</button>
    </div>
  );
}

export default Counter;
Angular
Syncity Service Example:


// syncity.service.ts
import { Injectable } from '@angular/core';
import SyncityClient from 'syncity-client';
import { BehaviorSubject } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class SyncityService {
  private client: any;
  public state$ = new BehaviorSubject<any>({});

  constructor() {
    this.client = new SyncityClient({ host: 'http://your-server.com' });
    this.client.on('init', (state: any) => this.state$.next(state));
    this.client.on('stateUpdate', (state: any) => this.state$.next(state));
  }

  updateState(payload: any) {
    payload.timestamp = Date.now();
    this.client.updateState(payload);
  }
}
Angular Component Example:


// counter.component.ts
import { Component, OnInit } from '@angular/core';
import { SyncityService } from './syncity.service';

@Component({
  selector: 'app-counter',
  template: `
    <div>
      <h2>Counter: {{ state?.counter || 0 }}</h2>
      <button (click)="increment()">Increment</button>
    </div>
  `
})
export class CounterComponent implements OnInit {
  state: any;

  constructor(private syncityService: SyncityService) {}

  ngOnInit() {
    this.syncityService.state$.subscribe(state => this.state = state);
  }

  increment() {
    const newValue = (this.state.counter || 0) + 1;
    this.syncityService.updateState({ counter: newValue });
  }
}


Node.js
Server-Side Example:


// server.js
const SyncityClient = require('syncity-client');

const syncity = new SyncityClient({ host: 'http://your-server.com' });

syncity.on('init', (state) => {
  console.log('Initial state:', state);
});

syncity.on('stateUpdate', (state) => {
  console.log('Updated state:', state);
});

// Update state example
syncity.updateState({ serverCounter: 100, timestamp: Date.now() });
Next.js
Next.js Page Example:


// pages/index.js
import { useEffect, useState } from 'react';
import SyncityClient from 'syncity-client';

export default function Home() {
  const [state, setState] = useState({});

  useEffect(() => {
    const syncity = new SyncityClient({ host: 'http://your-server.com' });
    syncity.on('init', setState);
    syncity.on('stateUpdate', setState);

    return () => syncity.disconnect();
  }, []);

  const increment = () => {
    const newValue = (state.counter || 0) + 1;
    syncity.updateState({ counter: newValue, timestamp: Date.now() });
  };

  return (
    <div>
      <h1>Welcome to Syncity</h1>
      <p>Counter: {state.counter || 0}</p>
      <button onClick={increment}>Increment</button>
    </div>
  );
}
API Reference ⚡
Initialize Client:


new SyncityClient(options)
options.host: URL of your Syncity server.
Subscribe to Events:


syncity.on(event, callback)
init – Fired on initial state load.
stateUpdate – Fired on state updates.
error – Fired on errors.
Update State:



syncity.updateState(payload)
payload: An object containing your update data plus a timestamp for conflict resolution.
Plugin Architecture 🧩
Syncity is built to be lightweight and extensible. Create plugins to add custom functionality—like logging, analytics, or enhanced conflict resolution—without modifying the core. See our Plugin Guide for more details.

Comparisons 🔍
Syncity vs. Redux/Context API:
Redux and Context API manage local state but require additional libraries for real-time synchronization. Syncity provides both in a unified package.

Syncity vs. Firebase/Firestore:
Instead of relying on a backend-as-a-service, Syncity offers a self-hosted, unified API across client and server for full control.

Syncity vs. Collaborative Libraries (Yjs, ShareDB):
Beyond real-time editing, Syncity includes offline-first support and plugin extensibility, making it a comprehensive state synchronization solution.

Contributing 🤝
We welcome contributions!

Fork the repository: GitHub Repo
Read our guidelines: See CONTRIBUTING.md
Submit PRs or open issues: Help us improve Syncity and join our growing community.
License 📜
Syncity is licensed under the MIT License.

Get in Touch 📬
GitHub Repository: https://github.com/learnXplor/syncity
npm Package: https://www.npmjs.com/package/syncity
linkedin : www.linkedin.com/in/pallav-singh-developer