Socket
Socket
Sign inDemoInstall

@koy/vitual-dom

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @koy/vitual-dom

A virtual DOM algorithm.


Version published
Maintainers
1
Install size
36.8 kB
Created

Readme

Source

@koy/core

A virtual DOM algorithm.

Why I write this library?

Since vitual DOM is so popular and many library have realized it,and I write it's for that I want to buid an app with the most natural javascript funcitonal programming way, that means we should run some code on webWorker or some other parallel way. I should control my code and know what should put to there and what not, so It comes.

It may not the best vitual DOM algorithm, it just a way that I realize.

How do I design this library?

You means, What a virtual DOM algorithm contains? An Element, a diff logic and a patch method, so you got it here.

Element

I design it as a class if you are familiar with OOP, but we shouldn't think it's a class and think it as a Container, or malformed Functor without map. And, you can use of method to put your dom type to Element like this:

Element.of('div', {class: 'container'}, Element.of('h2', 'Welcome to koy'))

diff

The diff method can diff two Element and get their differences:

diff(
  Element.of('div', {class: 'custom-container'}, Element.of('h2', 'Welcome to @koy/vitual-dom')),
  Element.of('div', {class: 'container'}, Element.of('h2', 'Welcome to koy'))
) // [0: [type: 1, attributes: {class: 'custom-container'}], 2: [type: 0, text: 'Welcome to @koy/vitual-dom']]

patch

The patch method can put the patches we get from diff method to real dom.

Note: make sure you root dom node lastChild is your root Element.

const root = document.getElementById('app')
patch({0: [type: 1, attributes: {class: 'container'}]}, root) // can change root lastChild's className to container

Keywords

FAQs

Last updated on 10 Nov 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc