Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bradcypert/essence

A Virtual DOM implementation in Dart.
https://github.com/bradcypert/essence

dart dart-package hacktoberfest virtualdom

Last synced: 14 days ago
JSON representation

A Virtual DOM implementation in Dart.

Awesome Lists containing this project

README

        



Essence

Essence is a super-simple Virtual DOM implementation in Dart.

Essence can parse DOM-Strings into Essence Nodes.

Essence can diff Essence Nodes and provide a list of actions on how to go from NodeList A to NodeList B.

[![Pub Version](https://img.shields.io/pub/v/essence?include_prereleases&style=for-the-badge)](https://pub.dev/packages/essence)

## Usage

A simple usage example:

```dart
import 'package:essence/essence.dart';

main() {
var tree1 = TreeParser.parse("");
var tree2 = TreeParser.parse("");
TreeDiff.diff(tree1, tree2).forEach((action) => {
print(action.node);
print(action.selector);
});
}
```

More interesting perhaps, you can leverage those actions to make updates to an actual DOM. It's worth mentioning that these CSS selectors are unbounded by default. You can pass in a `currentSelector` to `TreeDiff`'s `diff` function to scope them.

```dart
import 'dart:html';
import 'package:essence/essence.dart';

main() {
// ideally, you'll generate these from dart:html's querySelector
// but you can create them programatically, too!
var element = Element.div();
element.className = 'root';
element.childNodes.add(Element.span());

var element2 = Element.div();
element.className = 'root';
element2.childNodes.add(Element.article());

var eleParsed = TreeParser.parseElement(element);
var ele2Parsed = TreeParser.parseElement(element2);
var actions =
TreeDiff.diff(eleParsed, ele2Parsed, currentSelector: '.root');
actions.forEach((action) {
// ideally, do the action instead of just printing it, but Ill leave the code for that up to you :)
print(
'${action is NodeDeletion ? "Delete" : "Insert"} ${action.node.type} at selector ${action.selector}');
});
}
```

For more examples, please see our tests.

## Features and bugs

Please file feature requests and bugs at the [issue tracker][tracker].

[tracker]: https://github.com/bradcypert/essence/issues