Giter Site home page Giter Site logo

jsfw's Introduction

FW

Very basic frontend framework created just for fun as a hobby :D

Examples

Given very basic example with counter

<div fw>
    <h1 fw:onclick="{{count}} += 1">
        <span>Hello, you clicked me {{count}} </span>
        <span if="{{count}}==1">time</span>
        <span if="{{count}}!=1">times</span>
    </h1>
    <h2>Time right now is: {{time}}</h2>
</div>
const fw = new FW()
const state = fw.addState({count: 0, time: new Date().toString()})

document.querySelectorAll("[fw]").forEach(el => fw.bootstrap(state, el))
setInterval(() => state.time = new Date().toString(), 1000)

Features

Variables

Variables are declared as {{variableName}} and they correspond to given path in state object.

They can be traversed just like normal objects, i.e. {{parent.property}}` and in case of arrays as `{{array.index}}`, i.e. `{{array.0}}.

Dynamic attributes

Attributes prefixed with fw: are considered dynamic and they alter original attribute without fw: prefix, i.e. fw:href="#{{activeRoute}}" sets href to {{activeRoute}}

Dynamic events

Just like attributes, events can be defined same way, with speciality that self variable is available during call and corresponds to framework object. For example: fw:onclick="alert({{count}}); return false;".

Conditionals

Each element can become conditional by adding if attribute. In case if is evaluated true, element is shown, otherwise becomes hidden. In addition to if attribute, then attribute can be specified as well, which contains code that is called and in case it returns a Promise awaited, before content is shown.

Hard ifs

Hard ifs are special case of conditional, where children of element won't listen to changes in state once parent element's condition is evaluated as false

Foreach loop

Each element can become looped by adding each="item in array" property. Children can then use {{item}} as a dynamic variable.

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.