# erste.js **Repository Path**: mirrors_f/erste.js ## Basic Information - **Project Name**: erste.js - **Description**: Your first choice for hybrid mobile applications - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-08 - **Last Updated**: 2026-05-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Erste # JavaScript view library for building performant hybrid mobile applications **erste.js is a zero-hype view library with an attitude. It’s built for achieving maximum performance on mobile devices.** ## Features - Lightweight, 10kb minified & gzipped - No dependencies - No magic, as declarative as it should be and no more. - No pitfalls - Clean, structured and approachable API ## Overview ```js // 1. Import erste, import {Component} from 'erste'; // 2. Create your application, class App extends Component { // 3. Arrange your view, template() { return `

0

`; } // 4. Create your methods, increment() { this.$('h1').innerText += 1; } decrement() { this.$('h1').innerText -= 1; } // 5. Bind your events. get events() { return { 'tap': { '.increment': this.increment, '.decrement': this.decrement } } } } // 6. Make your application run. new App().render(document.body); ``` ## Table of Contents * [Motivation](#motivation) * [Installation](#installation) * [Direct download](#direct-download) * [Using bower](#using-bower) * [Using npm](#using-npm) * [Builds with Closure Compiler](#builds-with-closure-compiler) * [Example application](#example-application) * [Building your first application](#building-your-first-application) * [The root view](#the-root-view) * [DOM Events](#dom-events) * [How DOM event management works](#how-dom-event-management-works) * [Creating other components](#creating-other-components) * [Lifecycle management of components](#lifecycle-management-of-components) * [Option 1: Declarative](#option-1-declarative) * [Option 2: Imperative with erste.js API](#option-2-imperative-with-erstejs-api) * [Option 3: Imperative with DOM API](#option-3-imperative-with-dom-api) * [Creating master and detail views, or introducing the ViewManager](#creating-master-and-detail-views-or-introducing-the-viewmanager) * [Going back to the master view](#going-back-to-the-master-view) * [The back gesture](#the-back-gesture) * [Conclusion](#conclusion) * [License](#license) ## Motivation Building applications should be straightforward and simple. Most of the frameworks used today fail hard at being simple, and they make the wrong compromises for marginal gains. A super declarative framework with a megabyte of size, one second boot time and thousands of questions on StackOverflow due to its obscure and unfamiliar API... is this familiar? We as application developers don't need fancy features that are only good on the paper or in meetup talks. We need an easy-to-use, reasonable API that gets out of the way. The cognitive load for the framework used should ideally be 0. Good luck with that when you want to distinguish between '<' and '&'. erste.js is a solemn approach to application development. It gives you the barebones to get started and doesn't try to steal the show from your application. It lets you focus on your own source code and gets out of the way. ## Installation ### Direct download - [Development version](https://raw.githubusercontent.com/dashersw/erste.js/master/dist/erste.js) - [Minified version - 12kb gzipped](https://raw.githubusercontent.com/dashersw/erste.js/master/dist/erste.min.js) ### Using bower ```bash bower install --save erste.js ``` ### Using npm ```bash npm install --save erste.js ``` ### Builds with Closure Compiler erste.js plays really well with Google Closure Compiler. It's actually built with Closure Compiler, so if you use Closure Compiler for your own application, you can also `goog.require` or `import` the source code of erste.js and use and compile it with your source code right away for minimal footprint and maximal performance. ## Example application Head over to [erste.js-demo](https://github.com/dashersw/erste.js-demo) for an example Cordova application built with erste.js that showcases all the features of erste.js. It's fortunately not a to do app, but an almost real life multi-view app for displaying fan posters of popular tv shows. You can learn how to build and manage complex view hierarchies, handle user events and make use of the included tab bar, navigation bar, side bar, pull to refresh component and infinite scroll component. The repository also features a `Gulpfile.js` that includes common tasks for building the application with ES6 and transpiling it through Babel. ## Building your first application GUI applications are built with component architectures in mind. This is not a latest trend but the way GUI architecture was defined over 40 years ago. So in erste.js, there is one single and simple building block — the `Component` class. Everything you see and touch in an application is a component in erste.js, but it also provides some special constructs that eases your development. The most imminent of these is the `View` class, which is the main class for presenting a full view — a container that fills the screen and hosts other components — with its own lifecycle. ### The root view Every application starts with a root view. It is the first thing you put in your `` tag, a single view that includes all of your application. Write your root view by extending from the `View` class in erste.js; `root-view.js`: ```js import {View} from 'erste'; class RootView extends View { template() { return `

Hello world!

`; } } ``` The only thing you need to override here is the `template` method. Note that templates are only markups in erste.js. They are not parsed for declarative syntax, so here the `` is just a tag. Since we are targeting modern, HTML5-compatible browsers, you can actually use custom tags for distinguishable markup. Otherwise, you can just use plain `
`s. Actually, any element will do fine as a template, and a block element makes sense as the root view. You now should insert this view into the DOM. There are two ways to do this, the simplest being; `index.js`: ```js import RootView from './root-view'; document.body.innerHTML = new RootView(); ``` This simply inserts the template of your component to the body. A more involved alternative is to manually render the DOM element for the view as in; `index.js`: ``` import RootView from './root-view'; new RootView().render(); ``` Note that, the render method, when provided no arguments, renders this view directly into `document.body`. Alternatively, one may wish to pass in the desired host element as the first argument to the render method as in `new RootView().render(document.body);` We will discuss the implications of both approaches in a further topic. ### DOM Events Handling DOM events is completely automated in erste.js. We acknowledge that most of the bugs and problems arise due to poor handling of DOM events (especially when one forgets to remove them which leads to memory leaks). Moreover, manual DOM listeners hinder the performance of your application. Therefore, erste.js provides a complete event management system that fixes all of these problems for you in a declarative and extremely performant way. erste.js also has a built-in gesture recognizer that provides touch events like `tap`, `longTap`, `swipe` and more. Let's listen to the tap event on the button in our root view and do something meaningless with it; `root-view.js`: ```js import {View} from 'erste'; class RootView extends View { template() { return `

Hello world!

`; } onTapButton() { this.$('h1').innerText = 'Thanks for the tap!'; } get events() { return { 'tap': { 'button': this.onTapButton } } } } ``` The first thing you'll notice here is the declaration of the `events` property. It's an object whose keys are event types and values are another object with keys corresponding to CSS selectors and values corresponding to event handlers. Secondly, the manual DOM update. erste.js doesn't provide you with any data-binding functionality. Data-binding is, no matter what technique you employ, always a poor performer. Since the goal of erste.js is to be the most performant way of building apps, we decided against using declarative DOM updates and went for manual updates. However, this brings about the question of efficacy, as the horrible problems due to poor handling of jQuery code is still fresh in some memories. There are indeed horrible ways of managing the DOM manually, and we want you to stick to the best practices without compromising convenience. Therefore we provide two helper methods, `$` and `$$`. As you might have already guessed, these are simple wrappers around `querySelector` and `querySelectorAll` DOM APIs. These calls are also scoped, meaning `this.$('button')` actually translates to `this.el.querySelector('button')` where `this.el` is the DOM element of the component. This is a very efficient and straightforward way of referencing DOM elements. ### How DOM event management works erste.js provides a declarative method for managing DOM events, by heavily utilising event delegation. In erste.js, there's one global event handler for each DOM event type. When an event occurs, its global handler receives it and checks if there are any appropriate handlers defined in a component. If such a component is found, the event is forwarded to the designated handler. Although event management is delegated to global handlers on the body, event propagation still works as it's supposed to. This lets you use the regular event handling approach you are accustomed to from classical web development where parent components may listen to events that happen on their children. ## Creating other components erste.js doesn't mess with your lifecycle management. Creation of additional views and components is strictly imperative, meaning you get to instantiate your views manually and whenever you want. We acknowledge that a key step in optimization of mobile apps is manually managing the instantiation and disposal of hefty components, so we simply leave it to you. Let’s turn our simple button and label into a standalone component. `button-with-label.js`: ```js import {Component} from 'erste'; class ButtonWithLabel extends Component { template() { return `

Hello world!

`; } onTapButton() { this.$('h1').innerText = 'Thanks for the tap!'; } get events() { return { 'tap': { 'button': this.onTapButton } } } } ``` We basically moved all the logic into a reusable component. An important thing to note here is, the `template` method should return a single HTML element. Therefore, we wrapped our `

` and `