GithubHelp home page GithubHelp logo

component-4's Introduction

About The Project:

In this project I'm trying to make my own web librart that using component alike angular. Here is why:

  • I don't like jsx like syntax
  • It help me understand the way how other libraries like angular or react works

Demo

Built With:

  • HTML/CSS
  • JavaScript

Getting Started

Included these files into your html file:

<script src="js/anvil4.js"></script>
<script src="js/script.js"></script>

Usage:

You just need only file anvil4.js to use this library.

Folder structure

.
└── project/
    ├── js/
    │   ├─ anvil4.js
    │   └─ script.js
    ├─ helloUser.package
    └─ index.html

Create a helloUser.package file: Package file starts with <package> tag:

<package>
    <!--Your component goes there-->
</package>

Then we need a name for our component so that we can call when needed. There we using <component> tag. <component> has a attribute named *name to set the name of the component

<component *name="MyComponent">
    <!--Your render logics goes there-->
</component>

And the most important thing for the component is its parameters which is also called props. With parameters we can pass value into the component. So, the component can be reusing. For the parameters we using <prop> tag to decalre. <prop> also have *name attribute to set the name of the parameters. So our <prop> will looks like:

<props *name="Username"></props>

Each component can have many of parameters And the last one that you need to care about is the <render> tag. This tag will render what you want user to see with the passed parameters. Within the <render> you can put your logic into the {{ /* logic codes */ }} brackets. Example:

<div>
    Username is: {{Username}}
    <div></div>
</div>

You can access the passed parameters in your props tags through this.props.ParameterName After all you code will looks like this:

<package>
    <component *name="MyComponent">
        <props *name="Username"></props>
        <render>
            <div>Username is: {{Username}}<div>
        </render>
    </component>
</package>

The final step is load the package file into your code. Put the code below into script.js file

function ComponentInit() {
    this.load.fromPack("../helloUser.package", true);
}

function HandleInit() {}

const anvil = new Anvil({
    init: {
        ComponentInit: ComponentInit,
        HandleInit: HandleInit,
    },
});

After these steps, you can now call the component inside your html file directly. Like this:

inedx.html

<html>
    <body>
        <MyComponent Username="Fuong"/>
        <script src="js/anvil4.js"></script>
        <script src="js/script.js"></script>
    </body>
</html>

Every time the props chang. There will be a differ to check which node Element is changed and then update the needed nodes only.

component-4's People

Contributors

phuong74200 avatar

Watchers

James Cloos avatar  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.