GithubHelp home page GithubHelp logo

adpeyre / jaspp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alavieille/jaspp

0.0 0.0 0.0 155 KB

Lightweight JavaScript library for building javascript application

JavaScript 77.22% CSS 20.52% HTML 2.25%

jaspp's Introduction

Jaspp

Version License Downloads Filesize CircleCI codecov

Jaspp is Lightweight JavaScript library for handle javascript in a website.

  • Tiny < 3kb
  • 0 dependencies
  • Component oriented

Example

Todo List

Getting Started

Install Jaspp with npm or yarn:

npm install jaspp

Create a component to handle javascript of a DOM Element

//components/YourComponent.js

import {AbstractComponent} from 'jaspp'

class YourComponent extend AbstractComponent 
{
    render(el) {
        // handle javascript of el element
    }
}

Create Application and register your components

//index.js
import {Application} from "jasp";
import YourComponent from "components/YourComponent.js";

const components = {
    'YourComponent' : YourComponent
};

const app = new Application(components);

app.start();

If you use webpack, you can use class ComponentsLoader to load automatically all components inside a folder

import {Application, ComponentsLoader} from "../../dist/index.js";

// load all components inside components folder
const components = ComponentsLoader.import(require.context('./components/', true, /\.js$/));
const app = new Application(components);

// ...

Activate a component on specific DOM Element with data attribute data-view-component and component's name.

<div data-view-component="YourComponent">
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  </p>
</section>
Events

Different events are available in Application:

  • before:start is dispatch before render of components
  • after:start is dispatch after render of components
  • error is dispatch when there is an error inside a component, it's can be util to log error.
//index.js

// ...

const app = new Application(components);

app.start();

app.addEventListener('before:start', (app) => {
  console.log('Application before start event');
});

app.addEventListener('after:start', (app) => {
  console.log('Application after start event');
});

app.addEventListener('error', (exception) => {
  console.log('Application after start event');
});

  • dom.update This event enables components on dynamically added HTML.
import {AbstractComponent} from 'jaspp'

class YourComponent extend AbstractComponent 
{
    render(el) {
       const template = `
          <div id="example" data-view-component="OtherComponent"></div>
       `;
       el.insertAdjacentHTML('beforeend', template);
       this.application.dispatch('dom.update', el.querySelector(#example));
    }
}

jaspp's People

Contributors

alavieille avatar

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.