1.2.10 • Published 2 years ago

@rackai/domql v1.2.10

Weekly downloads
106
License
-
Repository
github
Last release
2 years ago

DOMQL

DOM rendering Javascript framework.

  • Minimalistic
  • No dependencies
  • Extendable
  • No transpilations, simple ES6 code
  • One-time import and subtrees

You can start with starter-kit as a boilerplate, or jump into the live editor playground.

npm version Build Status Coverage Status

Key features:

  • error reporting
  • virtual DOM tree
  • create
    • create using prototype class
    • support multiple level prototypes
    • DOM caching
  • state
  • binding
    • with other component
    • with state
  • update
    • set (recreate)
    • only iterate with diff
  • events
    • event handling
    • bubbling and propogation
  • run changes inside animationFrame

Getting started

To install all dependencies and run dev server, run:

yarn && yarn start

Examples

Initialization:

import DOM from '@rackai/domql'

DOM.create({ text: 'Rendered' })

Attributes:

var link = {
  tag: 'a',
  class: 'menu link',
  attr: {
    href: '#'
  }
}
var img = {
  tag: 'img',
  class: 'avatar',
  attr: {
    src: '...'
  }
}

Reusing:

var Link = {
  tag: 'a'
}

var ListItem = {
  proto: Link,
  class: 'ui link',
  attr: {
    href: '#'
  }
}

var menu = {
  childProto: ListItem,
  home: 'Home',
  text: 'About'
}

var header = {
  logo: {},
  menu
}

Array Support:

var navItems = ['Home', 'About', 'FAQ', 'Contact']

var menu = {
  proto: ListItem,
  ...navItems
}

Update:

var val = {
  text: 0
}

var Increment = {
  tag: 'button',
  text: 'Increment',
  on: {
    click: (e) => {
      val.update({ text: val.text++ })
    }
  }
}

API

Properties

PropertyTypeDescriptionDefault
keyNumber StringDefines the key of the ElementThe key of the object, or randomly generated name
protoObject ArrayClones the other elementundefined
childProtoObject ArraySpecifies the proto for all child elementsundefined
tagStringSpecifis the HTML tagdiv or related HTML tag if the key matches
classAnySpecifies the HTML classundefined
attrObjectSpecifies the set of HTML attributes{}
textAnyText inside the elementundefined
contentObject ArrayFragment wrapper to use dynamic content loadingundefined

To specify your own property per Element, set the function inside define property like:

var User = {
  define: {
    username: param => param.toUpperCase()
  },
  text: element => element.username
}

var Contact = {
  proto: User,
  username: 'nikoloza'
}

Methods

MethodDescriptionParams
updateUpdates element by passed objectproperties: Object Array
setSets passed element in the content propertyelement: Object Array

Events

All native DOM events are supported and can be specified inside on parameter. Additionally, init and render can be also invoked. All events except these two receive event object as a first parameter, following the element object itself.

Reserved keywords

key
tag
node
proto
on
class
text
data
style
attr
update
set
define

Anything except these keywords will create a new nested child element. The easier method to specify HTML tag is to use related nodeName as a key, for example:

var layout = { // this will be <div>
  header: {}, // will create <header>
  aside: {}, // will create <aside>
  main: { // will create <main>
    childProto: {
      article: { // will create <article>
        title: {}, // will create <div>
        description: {}, // will create <div>
        _rating: {} // will create <div class="rating">
      }
    }
  },
  footer: {} //  will create <footer>
}

Credits

Inspired by brisky

1.2.8

2 years ago

1.2.9

2 years ago

1.2.10

2 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.9

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.1.0

3 years ago

0.1.1

3 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.1

4 years ago