jadejs
Jadejs is a light front-end framework build over vanilla JavaScript using component pattern. Jadejs is build over ECS5 features.
Installation
npm install jadejs
Import in index.html
Documentation
Creating of a new Jade app is simple.
var app = app || {};{ app = selector : "my-app" ;}app;
Create root element of our app in index.html
Now we have our Jade app...
Creating modules
After we created our Jade app, lets create our first module.
// Creating new Modulevar baseUrl = "http://localhost:4200/"var appRoutes = url: baseUrl + "#/" component : "IndexComponent" url : baseUrl + "#/home" component : "HomeComponent" ; app
This is how we create module. It will load all components which are presented in our component propery. Also we need to present routes which will be resolved by module and load component which are identically to the route.
Creating component
After we created our Jade app, lets create our first component.
// Creating new Componentapp; //Main logic component function { var pageHeader = HomeService; scopepageHeader = pageHeader;};
Load templateUrl and template
template:'<h1 jmodel="pageHeader"></h1>'
You can render HTML directly in the component using template OR...
templateUrl:'app/components/home.component.html'
You can use templateUrl to load static html file and render it.
What is scope object?
scope object is the communication between component and tempalte/view html. You can easly assign values to this object and display it on page. Scope object is two way binding object which observe the state of the assigned objects on it and update the values in models.
{ var pageHeader = HomeService; scopepageHeader = pageHeader;};
Visualisation
-- jfor
We can easly render collections using jfor html helper
{ scopeusers = firstName : "John" lastName : "Mannuel" firstName : "Peter" lastName : 'Peterson' firstName : "Abby" lastName : "Simpson" ;};
{users.firstName} {users.lastName} {user.name} Details
-- jvm
jvm html helper is using for representing of view model - j view model
{user.name} {user.id} {user.name} Details
We can also use the anotation for attributes like href="{user.id} will be replaced with id from the user object" You can easly use it for single object or...
{title}
-- jclick
jclick html helper allow us to bind function which will be invoked from component and trigger the behaviour of it when you click on element wher it is binded.
{ scope{ approuter; }};
Click to redirect
You can use it for single property like scope.title = "Page Title".
-- jif
jif html helperer allow us to build logical operations over html elements like standart if staitment-
No users to display Users list {users.firstName} {users.lastName}
What is jmodel and jbind and how to use it?
jmodel creating properies which we use to store information via html and use it in our component.
jbind is representation notation for displaying objects and properties on our page. Everything typed in jmodel="pageHeader" will be automatically updated in jbind model
'
Invocation of component by selector
We can easly invoke whole component in our html everywhere by calling the selector of the component. This will load whole component class, services and providers functionality required for this component.
Creating a new injectable service
app;{ { return Http; }; return getUserData : getUserData ;};
Creating of service require serviceClass function which is our main function. In this case we need to review all public functions which we want to invoke in out component in return object.
We have providers which are comming out of the box for you and can be injected in services and components..
Providers
Http
Http provider can be injected in components and services. Helping us to make API requests. Every Http request returning promise as a result.
Http;Http;Http;Http;
Parameters URL - request url as string data - POST data which will be sended to API. headerOptions - Array of Objects wich help to configure request headers parametes.
var headerOptions = name : "Content-Type" value : "application/json";Http;
Cookie
Cookie provider can be injected in components and services. Helping us to store and get data from browser cookies.
Cookie // Set new cookie with name , value and expiration days / timeCookie; // Get cookie by name
Working with route with query params
var baseUrl = "http:\\localhost:4200"var appRoutes = url : baseUrl + "#/details/?id" component : "DetailsComponent" ;app
Everything after "?" char is query and will be replaced with url value Example http://localhost:4200/#/details/1
How to access and work with url params?
app{ var id = approuterparams"id"; scopeuser = UserService;}
Redirect to url
In the example we will trigger redirection to the Home page.
app{ approuter}
In development
- Implement support of more modules
- Implement more html helpers
Development
Want to contribute? Great! You can check my github https://github.com/DanielJelev/jade or... Contact me on danieljelev93@gmail.com for more info.
License
MIT
Free Software, Hell Yeah!