data-mirror
v0.0.2
Published
Sync data across *any* boundaries.
Downloads
138
Readme
data-mirror
Sync data across any* boundaries.
* = Browser tabs, windows, contexts, out of the box. Extensible for everything else!
Motivation 💥
data-mirror is a tool to synchronize data. It is extensible and can be used in various scenarios. Out of the box, it provides ways to synchronize within one window or across multiple tabs or windows (browser contexts).
Features 🔥
✅ Synchronize data
✅ Framework agnostic
✅ Hashing for data comparison
✅ Synchronize with callbacks
✅ Synchronize within one window
✅ Sync across multiple tabs or windows (browser contexts)
✅ Extensible for custom synchronization scenarios
Built With 🔧
Installation 📦
pnpm i data-mirror
// or
yarn add data-mirror
// or
npm i data-mirror
Usage Example 🚀
import { DataMirror } from 'data-mirror';
const sync = new DataMirror('my-sync', a => a);
sync.listenForChanges(value => {
console.log('new value:', value);
});
sync.update('test value');
With strategies
import { DataMirror } from 'data-mirror';
const sync = new DataMirror('my-sync', a => a).withStrategy(
new DataMirrorWindowStrategy(),
new DataMirrorBroadcastStrategy()
);
Implement a custom strategy
import { DataMirrorStrategy, Payload } from 'data-mirror';
export class DataMirrorBroadcastStrategy<T> extends DataMirrorStrategy<T> {
public init() {
// Initialize the strategy
}
public onUpdate(payload: Payload<T>) {
// Handle the update to inform the remote instances about the change
}
}
Contributing 🧑🏻💻
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License 🔑
Distributed under the MIT License. See LICENSE.txt
for more information.
Contact 📧
Janik Schumacher - @LoaderB0T - linkedin
Project Link: https://github.com/LoaderB0T/data-mirror