Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/littlstar/chasma

Application Screen Management
https://github.com/littlstar/chasma

Last synced: about 1 month ago
JSON representation

Application Screen Management

Awesome Lists containing this project

README

        

# chasma

Basic application screen management

*chasma* helps you structure your views.

## install

With npm:

```sh
$ npm install chasma --save
```

With duo:

```js
import * as chasma from 'littlstar/chasma';
```

## usage

*chasma* offers a `Screen` class that can be subclassed.
A screen may have children. A screen may also have a parent. A screen
can listen for and dispatch arbitrary events.

```js
class MyView extends chasma.Screen { }
```

## example

In this example we'll crean a base view screen class and extend it for
subclass views. Our base view class will be responsible for wrapping a
DOM element and knowning how to render it to a given screen instance.
We've also overloaded the `chasma.Screen` class's `appendChild()` and
`removeChild()` methods for DOM manipulation.

Our base class could look like this:

```js
class BaseScreen extends chasma.Screen {
constructor (domElement = null) {
super();
this.domElement = domElement || document.createElement('div');
}

appendChild (child, ...args) {
this.domElement.appendChild(child.domElement);
return super.appendChild(child, ...args);
}

appendChild (child, ...args) {
this.domElement.removeChild(child.domElement);
return super.removeChild(child, ...args);
}
}
```

We can now subclass and create a DOM element and pass it to the super
class constructor. We will also define an `add()` method for creating
menu items. Our menu items will also be subclasses of `BaseScreen`.

Our menu item screen class could look like this:

```js
class MenuItem extends BaseScreen {
constructor (opts = {}) {
super(createDom(`


  • ${opts.content}

  • `));
    }
    }
    ```

    and our menu class would look like this:

    ```js
    class Menu extends BaseScreen {
    constructor () {
    super(createDom('