Git Product home page Git Product logo

essence's Introduction

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

Usage

A simple usage example:

import 'package:essence/essence.dart';

main() {
  var tree1 = TreeParser.parse("<a></a>");
  var tree2 = TreeParser.parse("<b></b>");
  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.

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.

essence's People

Contributors

bradcypert avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

essence's Issues

CSS Selectors should be more specific

Currently, our CSS selectors from diffing are very, very abstract. For example, diffing:

<div>
  <span></span>
</div>

against

<div>
  <h1></h1>
</div>

Will return two actions, each with selectors that look like *:nth-of-type(0) > *:nth-of-type(0).

Ideally, we'll be able to return something like div:nth-of-type(0) > span:nth-of-type(0) and div:nth-of-type(0) > h1:nth-of-type(0) instead.

Most of the changes for this will need to be made in tree_diff.dart, specifically around action generation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.