deltamin

Creator: coderz1093

Last updated:

0 purchases

deltamin Image
deltamin Images

Languages

Categories

Add to Cart

Description:

deltamin

deltamin Δ #
Minify your Delta format data
before sending it down the wire
or saving it to a datastore.












Note: this project is still very much a "work-in-progress".
We need your help to ensure that the keyword list is complete.
If you are using the Delta format and want to help with deltamin,
check /lib/index.js#L4 and confirm all the keywords are there.
If you find a keyword in Delta that isn't in the

map,
please leave a comment on:
deltamin/issues/1
Why #
The Delta format https://quilljs.com/docs/delta is quite verbose:
const delta = new Delta([
{ insert: 'Gandalf', attributes: { bold: true } },
{ insert: ' the ' },
{ insert: 'Grey', attributes: { color: '#ccc' } }
]);
copied to clipboard

From the Developer perspective,
having a verbose format makes perfect sense
because it's easy to understand at a glance what is going on.
Given that computers are more than fast enough
to process this verbose format,
it won't affect the performance
of any app using the Delta format.
Where we feel there is scope for improvement is in:
a) data transmission
i.e. saving bandwidth for people who don't have a lot of it
b) saving complete history of changes so that they can be replayed
We can minify this to:
const delta = new Delta([
{ i: 'Gandalf', a: { b: true } },
{ i: ' the ' },
{ i: 'Grey', a: { c: '#ccc' } }
]);
copied to clipboard

(157 - 117 / 157) = 25% bandwidth saving.
It might not feel like much of a saving in this trivial example,
but if you scale it up to entire documents
and thousands (millions?) of concurrent people using a collaborative editor,
a 25% saving on a $10k/month bandwidth bill is $30k/year!
Saving bandwidth is the right thing to do for the World!
Why should anyone needlessly waste any scarce resource?
Obviously this is micro-bandwidth saving is meaningless
in a world where
Google Stadia
is server-rendering and streaming 4K games in realtime ... 🤦
But we can only try to set a good example to follow.
How? #
Javascript #
Install the node.js dependency in your project:
npm install deltamin --save
copied to clipboard
Use it before sending the data to the server:
const deltamin = require('deltamin');
const data = deltamin.minify(delta);
channel.push('update', data);
copied to clipboard

Note: this example is for sending data via a Phoenix Channel.
See: https://github.com/dwyl/phoenix-chat-example

Dart #
You can use deltamin on the Dart ecosystem, as well!
To install it, simply add this to your pubspec.yaml file,
in the dependencies section.
dependencies:
deltamin: ^1.0.0
copied to clipboard
And run dart pub get.
Here's an example on how to use this package.

import 'package:deltamin/deltamin.dart';

void main() {

final delta = {
"insert": 'Gandalf',
"attributes": {"bold": true}
};


// Minify the delta object
Map<String, dynamic> minifiedDelta = minify(delta);

// Unminify the minified object.
// Should be the same as the original delta object
Map<String, dynamic> unminifiedDelta = unminify(minifiedDelta);

print(unminifiedDelta);
// { "insert": 'Gandalf', "attributes": {"bold": true} }
}
copied to clipboard

Warning:
Delta objects that have keys that are not mapped by this package
will not be minified/unminified,
and maintain their original state.
For example:
final delta = {
"insert": 'Gandalf',
"someother_attribute": "summat",
"attributes": {"bold": true}
};
final min = {
"i": 'Gandalf',
"someother_attribute": "summat",
"a": {"b": true}
};
copied to clipboard

Todo #HelpWanted #
You can help us finish this module
by going through the Delta spec and add all keywords to the map
in the lib/index.js file.
e.g: insert, retain, text, attributes, etc.

❌ Define short versions for all the keywords
e.g: i, r, t, a

✅ Make the minified keywords as short as possible
(that's the whole point of this project!)
✅ wherever there is a keyword that starts with the same character,
give priority to the keyword that appears most frequently in the format.
e.g: insert is used more often than import
so insert > i and import > im


❌ Add more examples to README.md

Port this to Elixir #
Similar to how our "Toy" project
/quotes
contains the code for Elixir, JavaScript and Dart
in a single repo.
More detail in:
issues#10
We need your help with this too. 🙏
Ideally we would have a JSON "Dictionary"
that allows us to keep the mapping defined in a single place.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.