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

angular-base-class

v0.0.6

Published

An AngularJS service for class creation with prototypical inheritance and mixins.

Downloads

4

Readme

angular-base-class

Build Status Dependencies DevDependencies Coverage Status npm

An AngularJS factory for simple class based inheritance with support for mixins

Table of contents

  1. Key features
  2. Installation
  3. Usage
  4. Running tests
  5. Credits
  6. License

Key features

  • Constructor definition is optional
  • Uses this._super('methodName', arguments) to call super class methods
  • Supports multiple inheritance by resolving correct this context in super() calls
  • Mixins can be injected and used by adding them to mixins: []
  • Does not override inherited mixins
  • Compatible with AngularJS 1.2.x - 1.5.x

Installation

  • npm
    • npm i angular-base-class --save
    • include a reference to node_modules/angular-base-class/angular-base-class.js
  • bower
    • bower install angular-base-class --save
    • include a reference to bower_components/angular-base-class/angular-base-class.js

Usage

  • Include angular-base-class.min.js in your project
  • Add module BaseClass as dependency to your AngularJS app
Default constructor
angular.module('App', ['BaseClass'])
	.factory('Mammal', ['BaseClass', function (BaseClass) {
		return BaseClass.extend({
			setAge: function (age) {
				this.age = age;
			},
			getAge: function () {
				return this.age;
			}
		});
	}])
	.factory('Dog', ['Mammal', function (Mammal) {
		return Mammal.extend({
			setAge: function (age) {
				this._super('setAge', age + 10);
			},
			getAge: function () {
				return 'Dog is ' + this._super('getAge') + ' years old';
			}
		})
	}])
	.controller('Ctrl', ['$scope', 'Dog', function ($scope, Dog) {
		$scope.dog = new Dog({age: 5});
		$scope.dog.getAge(); // Dog is 5 years old
		$scope.dog.setAge(8);
		$scope.dog.getAge(); // Dog is 18 years old
	}]);
Custom constructor
angular.module('App', ['BaseClass'])
	.factory('Mammal', ['BaseClass', function (BaseClass) {
		return BaseClass.extend({
			constructor: function (args) {
				this.age = args.age + 1;
			},
			setAge: function (age) {
				this.age = age;
			},
			getAge: function () {
				return this.age;
			}
		});
	}])
	.factory('Dog', ['Mammal', function (Mammal) {
		return Mammal.extend({
			constructor: function () {
				this._super('constructor', arguments);
			},
			setAge: function (age) {
				this._super('setAge', age + 10);
			},
			getAge: function () {
				return 'Dog is ' + this._super('getAge') + ' years old';
			},
		})
	}])
	.controller('Ctrl', ['$scope', 'Dog', function ($scope, Dog) {
		$scope.dog = new Dog({age: 5});
		$scope.dog.getAge(); // Dog is 6 years old
		$scope.dog.setAge(8);
		$scope.dog.getAge(); // Dog is 18 years old
	}]);
With mixins
angular.module('App', ['BaseClass'])
	.factory('mammalMixin', [function () {
		return {
			grow: function (number) {
				this.age += number;
			},
			getName: function () {
				return this.name;
			}
		};
	}]);
	.factory('Mammal', ['BaseClass', 'mammalMixin', function (BaseClass, mammalMixin) {
		return BaseClass.extend({
			constructor: function (args) {
				this.name = args.name;
				this.age = args.age;
			},
			setAge: function (age) {
				this.age = age;
			},
			getAge: function () {
				return this.age;
			},
			mixins: [mammalMixin]
		});
	}])
	.factory('Cat', ['Mammal', function (Mammal) {
		return Mammal.extend({
			getAgeAndName: function () {
				return 'Age: ' + this.getAge() + ' Name: ' + this.getName();
			}
		});
	}])
	.controller('Ctrl', ['$scope', 'Cat', function ($scope, Cat) {
		$scope.dog = new Cat({name: 'Meow', age: 5});
		$scope.dog.getAge(); // 5
		$scope.dog.setAge(8);
		$scope.dog.getAge(); // 8
		$scope.dog.getName(); // Meow
		$scope.dog.getAgeAndName(); // Age: 8 Name: Meow
		$scope.dog.grow(2);
		$scope.dog.getAge(); // 10

	}]);

Running tests

  • Get the source code and in project root directory:
    • npm install
    • npm run test

Credits

  • Some ideas were borrowed from the following:
    • Axel Rauschmayer - http://www.2ality.com/
    • http://backbonejs.org/

License

Licensed under the MIT license. Copyright (c) 2015 - 2016 Audrius Jakumavicius