Skip to content

mglazer-cengage/mag.js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MagJS

###Magnum JavaScript

###MAG = Modular Application Glue

####Simple dependency injection module service factory

Include the script into your page:

HTML Script TAG

<script type="text/javascript" src="//rawgit.com/magnumjs/mag.js/master/dist/mag.full-0.2.min.js"></script>

Examples

Create a Module:

Factory, Service, Control

Define a Module

they are inheritable and reusable

     var githubUser = mag.module('githubUserApp');

Define a factory

They do maintain state, they are instantiated with a 'new'

      githubUser.factory('GithubUser', function() {
        var GithubUser = function(data) {
          $.extend(this, {
            id: null,
            collection: [],
            status: 'NEW',
            isNew: function() {
              return (this.status == 'NEW' || this.id == null);
            }
          });
          $.extend(this, data);
        };
        return GithubUser;
      });

Define a service

They can be injected with factories. Use the [] style arguments when minifying

      githubUser.service('GithubUserService', function(GithubUser) {
        this.getById = function(userId) {
          return $.get('github.json?id=' + userId).then(
            function(response) {
              return new GithubUser(response);
            });
        };
      });

Define a control

They can be injected with services or factories. They relay data to the view via the 'Scope' first argument

      githubUser.control('gitUserInfo', function(Scope, GithubUserService) {
        GithubUserService.getById('magnumjs').done(function(data) {
          Scope.id = data.id;
        });
      });

[Try it out] (http://jsbin.com/hopokibi/edit)

About

MagnumJS - core code library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published