lega911 / angular-light

Alight is a library for building interactive MVVM web interfaces/applications. (project is deprecated)
MIT License
274 stars 43 forks source link

Alight declarative interface #210

Open rumkin opened 7 years ago

rumkin commented 7 years ago

Add declarative interface:

alight.namespace('ns')
.directive('name', {link})
.directives({
    dirName: {link}
})
.controller(name, fn)
.controllers({
    ctrlName(scope) {/*...*/}
});
// filters are the same

Namespace create alight new namespace or use existing. It is pretty and simple.

Extended example:

(function() {
    'use strict';

    alight.namespace('ns')
    .controllers({userCtrl, settingsCtrl});

    function userCtrl() {}
    function settingsCtrl() {}
})();
lega911 commented 7 years ago

Hi!

I don't very like this Angular 1 style, but I can add it to "ext" package. Also filters doesn't have namespace, controllers were removed, now direct-directives instead of them. Also filters and direct-directives can be located in scope, so you don't need always create namespaces, e.g.:

alight('body', {
  data: '',
  filter: (a, b) => a+b,
  directive: () => {}
})
rumkin commented 7 years ago

What is direct-directives? How to define it?

rumkin commented 7 years ago

Declarative interface is about to avoid ugly constructions like alight.directives.ns = alight.directives.ns || {}; in modular applications.

rumkin commented 7 years ago

And about namespaces itself. It very important to separate code into modules. Namespaces is the best trick to avoid conflicts. I have two different projects where I've realised toDate filters but they parsed different date formats which cause an error. This make me to rewrite one of the components.