ng-js
Angular JS micro version (for learning).
It's developed for fun and to learn internals of the AngularJS framework.
And also to have a light version of it to train other people,
because it's much more easier to explain something about 400 lines of code, then about 10 000 loc.
It's not for production, it's not tested well, and there was no effort to optimize performance, so it's slow.
DEMO
What's implemented
Only really basic features are implemented.
And they are implemented in a simplified form.
Also APIs may be different.
The list:
- predefined directives
- API for custom directives (
priority
,link
,terminal
andscope
properties are available) - controllers (slightly different syntax), nested controllers
- services (called factories in AngularJS) and values (shortcut)
- dependency injection and resolver (but only services and values could be injected)
- scopes, nested scopes
- watchers
- expressions and parser (unlike in AngularJS it's implemented with
eval
to simplify implementation) - compilation (tree traversal) and applying directives
- dirty checking and digest cycle
Next directives are predefined:
- ng-render (one-time binding)
- ng-bind
- ng-model
- ng-controller
- ng-init
- ng-repeat (just recompiling, no optimizations)
- ng-click
- ng-change
- ng-show
- ng-hide
- ng-class
What's not implemented
There are many features not implemented, mainly to not complicate the code.
It's simple actually to implement them within the built structure.
But it was decided it's superfluous when expressing the concept.
The list:
- modules and multiple ng-app
-
config
andrun
methods ng-include
- routing
-
$http
,$resource
,$q
,$timeout
,$interval
- events
- validations
- filters
Code statistics
The numbers are indicated without empty lines and included underscore methods.
What | How much |
---|---|
the core | 250 loc |
with directives | 400 loc |
JSHint stats:
There are 92 functions in this file.
Function with the largest signature take 3 arguments, while the median is 1.
Largest function has 8 statements in it, while the median is 2.
The most complex function has a cyclomatic complexity value of 6 while the median is 1.
So I hope it's easy to learn.
Author (Speransky Danil): Personal Page | LinkedIn | GitHub | StackOverflow