Git Product home page Git Product logo

jiafeijs's Introduction

๐Ÿฅ‘ Welcome to Jiafei JS ๐Ÿฅ‘

Jiafei JS is a lightweight WebComponent based library which provides a set of functionalities to build a webpage using JS Vanilla

Main features

  • Virtual DOM with diff algorithm to render only changes
  • Reactive Components with state.
  • Router class to handle urls in a SPA.
  • Simple subscription system to events (bind, unbind, subscribe...)
  • Attribute bindings.

Including CSS

We have different strategies to load CSS, you can check them here

Examples

Component({
  tagName: "my-button",
  stylesURL: "my-button.css"
},
class Button extends WebComponent {
  render() {
    return `
      <button>This is a button :D</button>
    `
  }
})
Component({
  tagName: "my-button",
  stylesURL: "my-button.css"
},
class Button extends WebComponent {
  init() {
    this.state = {
      count: 0,
    }
  }
  bind() {
    this.subscribe("button", "click", () => this.setState({ count: this.state.count + 1 }))
  }
  render() {
    return `
      <button>Total: ${this.state.count}</button>
    `
  }
})

jiafeijs's People

Contributors

ruzafa8 avatar

Stargazers

Cristian avatar

Watchers

 avatar

jiafeijs's Issues

Property Binding

A property binding is a way to include JavaScript code inside an HTML attribute.

To indicate it is a property binding, we have to enclose the attribute name in square brackets.

For example:

<my-component [user]="{'id': '4', 'name': 'John'}"></my-component>

Global scripts

Shadow DOM components doesn't load scripts which are outside them, so we need to add a logic to include global scripts in a component.

Html evaluations

html text has got evaluations on those two situations:

  • When an attribute is enclosed between "[]" (attribute binding). It is evaluated using WebComponent context.
  • Every attribute, is tried to be parsed as object, array or number.
    ADITIONAL: Any text enclosed between {{ }}, if that feature is already developed.

As we can see, every attribute is parsed to JSON automatically. Is it optimal? Is there any way to parse only when we know it is parseable? Or parse only when it is an attribute binding?

Html Text binding

When a text is enclosed between {{ and }}, be able to evaluate it, in the context of the WebComponent class.

Improve diff dom algorithm

The actual diff algorithm convert the DOM in an array to iterate over it.

There are better ways to iterate over it, such as using Tree Walkers

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.