• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

♻️ Tiny component structure for web applications

data-components

Tiny component structure for web applications

Sponsors

Thank you to all the sponsors for this project:


Lucas Motta

→ Sponsor my open source work

Install

$ npm install data-components --save

Or you can simply copy and paste the minified standalone version that lives under dist/

Features

Motivation

There are plenty of options to architect a web application out there but most of them often assume that you're working on a SPA. That alone will add a lot of stuff that you might not want at all. Data binding, custom messaging system and virtual DOM to name a few.

Sometimes you just need something simple to kick things off without having to worry about naming conventions and programming paradigms. That's how this library was born.

Usage

Let's implement the simplest todo list app.

<!-- Create our todo list element passing some initial values -->
<ul data-component="todo" data-values="foo,bar"></ul>

<!-- Let's use a input field to read the user input -->
<input data-component="input" placeholder="What to do?">

Ok, now that we have our markup in place, let's implement the application.

// Todo component
class Todo {
  constructor(el, options) {
    this.el = el;
    // Read from initial values
    this.todos = options.values.split(',');
    this.render();
  }

  // Add items to the list
  add(todo) {
    this.todos.push(todo);
    this.render();
  }

  // Render the list to the DOM
  render() {
    this.el.innerHTML = this.todos.map(todo => `<li>${todo}</li>`).join('');
  }
}

// User input component
class Input {
  constructor(el, options, sandbox) {
    const todo = sandbox.get('todo');

    // Submit value to "todo" component when hitting the enter key
    el.addEventListener('keydown', e => {
      if (e.keyCode === 13) {
        todo.add(el.value);
        el.value = '';
        el.focus();
      }
    });
  }
}

// Bootstrap components (UMD build exposes `components()`)
components({
  todo: Todo,
  input: Input
});

demo

It works with just a few lines of code 🎉

Check out the demo page for a slightly more complex example.

More

For more detailed instructions on how the project works and how to use it, please check the user guide.

License

MIT © Rafael Rinaldi


Buy me a ☕

More Repositories

1

hn-cli

📰 CLI to browse Hacker News
JavaScript
458
star
2

whereami

📍 Get your geolocation information using freegeoip.app
JavaScript
159
star
3

porreta

👍 Get funny words in Brazilian Portuguese
JavaScript
75
star
4

til

📓 Collection of things I learn daily
53
star
5

mdn

Man pages for web APIs using MDN
JavaScript
42
star
6

atomify

Automatically atomify your CSS (draft)
32
star
7

html-meta-tags

Generate HTML meta tags from JSON data.
JavaScript
28
star
8

responsive-styles

Use arrays as values to specify mobile-first responsive styles for CSS-in-JS projects
JavaScript
28
star
9

sound-manager

🔈 Keep sound management intuitive and organized
HTML
26
star
10

transitionable-routes

Perform transitions when changing routes with React Router
JavaScript
26
star
11

hold-up

✋ Wait until a given condition is true
JavaScript
22
star
12

loading-indicator

🚦 Simple and customizable command line loading indicator
JavaScript
19
star
13

npm-downloads

📦 Get download stats from any package published to npm
JavaScript
17
star
14

cheatsheets

📝 My personal list of cheatsheets
17
star
15

bookmarkletify

🔖 Convert JavaScript files to bookmarklets
Shell
16
star
16

group-by

Group a list of objects by a given field name (implemented with ES6 features)
JavaScript
14
star
17

hyper-terminal-tabs

Brings Terminal.app look and feel to Hyper
JavaScript
13
star
18

malaco

Malaco is a tool that consumes data from Sao Paulo's subway system and expose it in a normalized API
JavaScript
13
star
19

vimfiles

⚡ My Vim setup
Vim Script
11
star
20

pesticide.js

Easy way to debug the visible elements in a web page.
JavaScript
10
star
21

dotfiles

My personal ~/
Emacs Lisp
10
star
22

to-boolean

Convert strings to boolean.
JavaScript
10
star
23

unicorn

A simple command line color manager for working with Node.js.
JavaScript
9
star
24

google-maps-coordinate-parser

Coordinate parser for Google Maps urls.
JavaScript
7
star
25

hyper-papercolor

PaperColor theme for Hyper
JavaScript
7
star
26

brooklynjs

Simple bot that warns you when tickets for BrooklynJS are available
HTML
7
star
27

siga

Siga is a mobile web app whose main goal is to offer a single source of information for people who use Sao Paulo's subway system.
JavaScript
6
star
28

truco

♠️ Truncate strings.
JavaScript
5
star
29

x9

TypeScript
5
star
30

slush-web-app

🔧 Scaffold a web app with Slush.
JavaScript
5
star
31

combine-same-keys

Combine all properties sharing the same key into a single object
JavaScript
5
star
32

st-snippets

Snippets for SublimeText.
5
star
33

npm-search

🔍 Faster `npm search`
JavaScript
4
star
34

fla2img

Retrieves all the image files within your .fla files.
JavaScript
4
star
35

media-queries

↕️ CSS media queries based on Zurb's Foundation breakpoints
CSS
4
star
36

changes

📝 Keep track of your code releases.
Shell
3
star
37

fulfil

👌 Simple search suggestion using the Levenshtein distance algorithm.
JavaScript
3
star
38

matt.js

Simple string formatter based on the sprintf implementation.
JavaScript
3
star
39

guess-programming-language

Naive programming language guessing built on top of highlight.js
JavaScript
3
star
40

curlyq

Convert straight quotes to smart quotes
JavaScript
3
star
41

add-zero

0️⃣ Add a leading zero to a number.
JavaScript
3
star
42

phantom-url

👻 Node's native URL parser to work with PhantomJS.
JavaScript
2
star
43

gh-linguist

GitHub's linguist data base exposed as a Node.js module
Shell
2
star
44

broken-link

🔗 Check wether or not a link is broken.
JavaScript
2
star
45

data-attributes

Extract data attributes from a DOM node.
JavaScript
2
star
46

ty

Appreciate team members for taking the time to review your pull request
JavaScript
2
star
47

ere

Brainfuck script that will teach you what the hell is "Erê"
2
star
48

lazy-loader

A lazy loading engine for ActionScript.
JavaScript
2
star
49

slush-node-module

🔧 Scaffold a Node.js module with Slush.
JavaScript
2
star
50

fla2swf

Publish a list of .fla files in a batch.
JavaScript
1
star
51

day-with-suffix

1
star
52

n-times

Run a function N times
JavaScript
1
star
53

rafaelrinaldi

1
star
54

is-phantom

👻 Check if current running context is PhantomJS.
JavaScript
1
star
55

list

Handy way to manipulate lists.
HTML
1
star
56

flashtracer

Manage your Flash logs via command line.
Shell
1
star
57

nextjs-now

JavaScript
1
star
58

swf2html

Generate a HTML wrapper for your SWF file.
Shell
1
star
59

inject-markup

💉 Inject HTML into a web page.
JavaScript
1
star
60

selectable

TypeScript
1
star
61

css-in-js-talk

Talk given at Work & Co about CSS in JS
CSS
1
star
62

curlyq-website

TypeScript
1
star