npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

alicatejs

v0.1.1

Published

Single page, component oriented javascript framework that aims at eliminating logic in the templates.

Downloads

19

Readme

Single page, component oriented javascript framework that aims at eliminating logic in the templates.

Build Status Join the chat at https://gitter.im/dryajov/alicatejs

alicatejs

Getting started

To install alicatejs do npm install --save alicatejs.

Resources

Motivation

With the advent of new and evermore complex javascript frameworks, we've seen an explosion of templating engines. I believe that templates are a simplistic solution to a complex problem, and it introduces more problems that it solves.

Some problems with templates are:

  • Foreign syntax.
    • Doesn't integrate well with existing target language and as such is not easily debuggable
  • It's the wrong level of abstraction.
    • With some templates featuring a complete set of branching statements, your view logic ends up spilled all over the place, making it difficult to follow and maintain
  • It's inherently insecure.
    • All templating engines allow some level of arbitrary expression execution, which could rely on something like eval, or have a built in parser for such evaluations. Each approach presents varying levels of security risks, however they all require some level of manual sanitation of the expressions, which is error prone and requires the dev team to stay on top of reported security vulnerabilities with frequent updates and patches.

How does alicatejs solve this problems?

With alicatejs, all the logic from the template is gone. This is accomplished by attaching behaviors to HTML elements and controlling the rendering of the elements from the code. This is in turn accomplished by marking some of the desired elements with the data-aid attribute that the framework picks up and makes available in the code as alicatejs components. The components are sufficiently abstract as to be able to attach to a range of similar HTML elements, and at the same time sufficiently concrete as to not to allow creating invalid markup.

Core concepts

View

A View represents an alicate Component that has an unparsed html fragment (logicless template) associated. The View initiates the rendering of the components tree.

Container

A Container is basically a Component that is able to hold a colection of other components (including another container such as a View, Container or Repeater). It is possible to add components to it by directly adding them to the children array or to by using the add method on an existing instance.

Component

A Component is the building block of the framework, it is a class extended by the rest of the components in the framework. There are a range of components that will attach to a subset of similar html elements.

These components are:

  • Label
  • Input
  • Repeater
  • Button
  • Image
  • Select
Model

A Model is consumed by components, it provides an interface to interact with external data, it has a data property and get and set methods that access the underlying data. Models are two way bound, a change in the model's data will trigger an update of the associated Component (you have to use the set method), and a change on an updateble html element that the component is associated with, will update the underlying data (and all the registered subscribers). It is, what in some other frameworks is considered a View Model.

Html Fragment (logicless template)

An html fragment is any html element that is marked with the data-aid attribute, this attribute is used by the framework to bind components to the corresponding html elements. Html fragments are compiled into a template store. A template store is a hash object with the key being the template name, and the value, the html fragment to be rendered.

Hello World in Alicatejs

helloworld.js
    var Alicate = require('alicatejs'),
        Container = Alicate.Container,
        Label = Alicate.Label,
        Button = Alicate.Button,
        Select = Alicate.Select;

        var templateStore = {};
        templateStore['helloworld.html'] = '<div data-aid="hello">[THIS WILL BE REPLACED]</div>';
        var app = new AlicateApp({
            templateStore: templateStore,
            selector: '#myapp',
            index: 'my-view'
        });

        app.add(new View({
                id: 'my-view',
                templateName: 'helloworld.html',
                children: {
                    hello: new Label({
                        id: 'hello',
                        text: 'Hello World from Alicate!!'
                        })
                }
            })).start();

The snippet above demonstrates the core concepts of alicate in action.

An application that will attach it self to the #myapp selector, is constructed using my-view id as its index view. Once we have an application, we can start adding our views to the app, this will allow alicatejs to render it when the desired view is set active by calling the start method. Next a Label component is added as a child of the View. The Label will render the contents of its text property to the associated html element.

DI integration

Currently alicatejs provides DI through opium-ioc. In order to inject dependencies into your alicatejs components and views, a special array property is used - $inject. Any string listed in the $inject array will be interpreted as a dependency name, will be looked up in opiums-ioc registry and subsequently assigned to an existing property in your component. opium-ioc expects the property to be defined, otherwise no injection will be performed.

    var view;
    module.exports = Alicate.View.extend({
        templateName: 'app/scripts/ui/import-view/import-view.html',
        $inject: ['connectors'],
        connectors: null,
        children: [
            providersList
        ],
        initialize: function initialize() {
            view = this;
        },
        onEnter: function () {
            Alicate.View.prototype.onEnter.call(this);

            this.connectors.init().done(function (connectors) {
                providerListModel.set([]);
                providerListModel.set(connectors);
            });
        }
    });

In the above snippet, connectors will be injected into the view.

Injection happens in two places, the first time a component is bound and on each subsequent onEnter invocations.