angular2-now
Advanced tools
Comparing version 0.3.5 to 0.3.7
@@ -7,12 +7,14 @@ var angular2now = function () { | ||
Component: Component, | ||
Directive: Component, | ||
View: View, | ||
Inject: Inject, | ||
Controller: Controller, | ||
Service: Service, | ||
Filter: Filter, | ||
Injectable: Service, | ||
bootstrap: bootstrap, | ||
State: State, | ||
Component: Component, | ||
Directive: Component, | ||
ScopeShared: ScopeShared, | ||
ScopeNew: ScopeNew, | ||
View: View, | ||
Inject: Inject, | ||
Controller: Controller, | ||
Service: Service, | ||
Filter: Filter, | ||
Injectable: Service, | ||
bootstrap: bootstrap, | ||
State: State, | ||
@@ -27,3 +29,3 @@ options: options, | ||
var $q = inj.get('$q'); | ||
var $log = inj.get('$log'); | ||
//var $log = inj.get('$log'); | ||
@@ -85,2 +87,36 @@ var currentModule; | ||
// Cancels out the automatic creation of isolate scope for the directive, | ||
// because Angular 1.x allows only one isolate scope directive per element. | ||
// This is useful when actually creating directives, which add behaviour | ||
// to an existing element, as opposed to components which are stand alone | ||
// bits of html and behaviour. | ||
// The other way to do this is to pass "scope: undefined" to @Component. | ||
function ScopeShared (target) { | ||
target.scope = undefined; | ||
return target | ||
} | ||
// Requests a new scope to be created when the directive is created. | ||
// The other way to do this is to pass "scope: true" to @Component. | ||
function ScopeNew (target) { | ||
target.scope = true; | ||
return target | ||
} | ||
//function Directive(options) { | ||
// | ||
// // A string passed is assumed to be the attribute name of the directive. | ||
// if (typeof options === 'string') | ||
// options = { selector: options }; | ||
// | ||
// // Directives have shared scope by default (scope:undefined). | ||
// // Optionally they can have a new scope created (scope: true). | ||
// // If you require an isolate scope for your directive then | ||
// // pass "scope: { ... }" in options. | ||
// if (options && !options.hasOwnProperty('scope')) | ||
// angular.merge(options, { scope: undefined }); | ||
// | ||
// return Component(options); | ||
//} | ||
function Component(options) { | ||
@@ -186,5 +222,5 @@ options = options || {}; | ||
._invokeQueue | ||
.find(function (v, i) { | ||
.filter(function (v, i) { | ||
return v[0] === '$provide' && v[2][0] === serviceName | ||
}); | ||
})[0]; | ||
} | ||
@@ -206,13 +242,34 @@ | ||
function Inject(deps) { | ||
if (typeof deps !== 'undefined' && !(deps instanceof Array)) { | ||
throw new Error('@Inject: dependencies must be passed as an array.'); | ||
// 2015-09-01 Replaced the whole Inject function with a new more flexible version. | ||
// Thanks to Steven Weingärtner for his code, which works with both Classes and Methods, | ||
// as well as preserving injectables from a parent class (when extending a parent class). | ||
// New features: | ||
// - Dependencies can be passed in as arguments, not requiring the array wrapper. The | ||
// original syntax with the array wrapper is still supported. | ||
// - Methods of a class can now be Injected also | ||
// - Child classes will inherit the parent class's injectables, which will be appended | ||
// to the end of the child's dependencies | ||
function Inject() { | ||
var deps; | ||
if (arguments[0] instanceof Array) | ||
deps = arguments[0]; | ||
else | ||
deps = Array.prototype.slice.call(arguments); | ||
if (deps.length === 0) { | ||
throw new Error('@Inject: No dependencies passed in'); | ||
} | ||
deps = deps || []; | ||
return function (target, name, descriptor) { | ||
var injectable = target; | ||
if (descriptor) | ||
injectable = descriptor.value; | ||
return function (target) { | ||
if (!target.$inject) | ||
target.$inject = []; | ||
if (!injectable) | ||
throw new TypeError('@Inject can only be used with classes or class methods.') | ||
var existingInjects = injectable.$inject; | ||
injectable.$inject = []; | ||
angular.forEach(deps, function (dep) { | ||
@@ -224,7 +281,12 @@ // Namespace any injectables without an existing nameSpace prefix and also | ||
if (target.$inject.indexOf(dep) === -1) | ||
target.$inject.push(dep); | ||
if (injectable.$inject.indexOf(dep) === -1) { | ||
injectable.$inject.push(dep); | ||
} | ||
}); | ||
return target; | ||
if (existingInjects) { | ||
injectable.$inject = injectable.$inject.concat(existingInjects); | ||
} | ||
return descriptor || target; | ||
}; | ||
@@ -234,4 +296,2 @@ } | ||
//var _templateCacheTranscluded = {}; | ||
function View(options) { | ||
@@ -259,23 +319,2 @@ options = options || {}; | ||
// Check for <content> in cached templates | ||
//if ('undefined' === typeof Meteor) | ||
// var _templateCache = angular.injector(['ng', currentModule]).get('$templateCache'); | ||
//else | ||
// var _templateCache = angular.injector(['ng', 'angular-meteor', currentModule]).get('$templateCache'); | ||
// | ||
//if (target.templateUrl && !_templateCacheTranscluded[target.templateUrl]) { | ||
// var template = _templateCache.get(target.templateUrl); | ||
// if (template && /<content/i.test(template) && !/<content ng-transclude/i.test(template)) { | ||
// template = transcludeContent(template); | ||
// _templateCache.put(target.templateUrl, template); | ||
// | ||
// $log.log('@@ Adding ng-transclude to: ', target.templateUrl); | ||
// | ||
// // Remember that we have already transcluded this template and don't do it again | ||
// _templateCacheTranscluded[target.templateUrl] = true; | ||
// } | ||
// //else | ||
// // throw new Error('@View: Invalid templateUrl: "' + target.templateUrl + '".'); | ||
//} | ||
return target; | ||
@@ -369,2 +408,6 @@ }; | ||
// Mark this class as a bootstrap component. This allows @State | ||
// to handle it correctly. | ||
target.bootstrap = true; | ||
var bootModule = target.selector || currentModule; | ||
@@ -403,3 +446,3 @@ | ||
* name: name of the state | ||
* url: url associted with this state | ||
* url: url associated with this state | ||
* template: template | ||
@@ -412,4 +455,4 @@ * templateUrl: templateUrl | ||
* params: Literal object, see ui-router doco | ||
* controller: A controller is automaticaly assigned, but if you nee | ||
* finer control then you can assign your won controller | ||
* controller: A controller is automatically assigned, but if you need | ||
* finer control then you can assign your own controller | ||
* | ||
@@ -491,4 +534,4 @@ * If a class is annotated then it is assumed to be the controller and | ||
// The bootstrap component should always be abstract, otherwise weird stuff happens. | ||
// The State applied to a bootstrap component can be abstract, | ||
// if you don't want that state to be able to activate. | ||
abstract: options.abstract, | ||
@@ -498,4 +541,12 @@ | ||
// If this is an abstract state then we just provide a <div ui-view> for the children | ||
template: options.templateUrl ? undefined : options.template || (options.abstract ? '<div ui-view=""></div>' : target.selector ? '<' + target.selector + '></' + target.selector + '>' : ''), | ||
// This is the "inline" template, as opposed to the templateUrl. | ||
// 1) If options.templateUrl is specified then template will be set to undefined. | ||
// 2) If options.template is provided then it will be used. | ||
// 3) Otherwise, if this is a component, but not the bootstrap(**) component, | ||
// then we use it's selector to create the inline template "<selector></selector>". | ||
// 4) Otherwise, we provide the following default template "<div ui-view></div>". | ||
//(**) The bootstrap component will be rendered by Angular directly and must not | ||
// be rendered again by ui-router, or you will literally see it twice. | ||
// todo: allow the user to specify their own div/span instead of forcing "div(ui-view)" | ||
template: options.templateUrl ? undefined : options.template || ((target.template || target.templateUrl) && !target.bootstrap && target.selector ? target.selector.replace(/^(.*)$/, '<$1></$1>') : '<div ui-view=""></div>'), | ||
@@ -506,6 +557,4 @@ // Do we need to resolve stuff? If so, then we also provide a controller to catch the resolved data. | ||
// A user supplied controller OR | ||
// A class, if no Component was annotated (thus no selector is available) OR | ||
// A proxy controller, if resolves were requested with an annotated Component | ||
// An internally created proxy controller, if resolves were requested for a Component. | ||
controller: userController || (doResolve ? controller : undefined), | ||
//controller: options.controller || (!target.selector ? target : undefined) || (doResolve ? controller : undefined) | ||
@@ -517,2 +566,3 @@ // onEnter and onExit events | ||
// Create the state | ||
@@ -601,3 +651,3 @@ $stateProvider.state(options.name, sdo); | ||
// Create a method that calls the back-end | ||
target[name] = function () { | ||
descriptor.value = function () { | ||
var argv = Array.prototype.slice.call(arguments); | ||
@@ -638,3 +688,3 @@ var deferred = $q.defer(); | ||
return target; | ||
return descriptor; | ||
} | ||
@@ -641,0 +691,0 @@ |
Package.describe({ | ||
name: 'pbastowski:angular2-now', | ||
version: '0.3.5', | ||
version: '0.3.7', | ||
summary: 'Use Angular 2 @Component syntax with Angular 1 and Babel', | ||
@@ -11,6 +11,6 @@ git: 'https://github.com/pbastowski/angular2-now.git', | ||
api.versionsFrom('1.1.0.2'); | ||
api.use('urigo:angular@0.9.2', 'client'); | ||
api.use('pbastowski:angular-babel@0.1.8', 'client'); | ||
api.imply('urigo:angular@0.9.2', 'client'); | ||
api.imply('pbastowski:angular-babel@0.1.8', 'client'); | ||
api.use('angular@1.0.0-rc.5', 'client'); | ||
api.use('pbastowski:angular-babel@0.1.9', 'client'); | ||
api.imply('angular@1.0.0-rc.5', 'client'); | ||
api.imply('pbastowski:angular-babel@0.1.9', 'client'); | ||
api.addFiles(['angular2-now.js', 'exports.js'], ['client']); | ||
@@ -21,5 +21,5 @@ api.export(['angular2now']); | ||
Package.onTest(function (api) { | ||
api.use('tinytest'); | ||
api.use('pbastowski:angular2-now'); | ||
api.addFiles('angular2-now-tests.js'); | ||
//api.use('tinytest'); | ||
//api.use('pbastowski:angular2-now'); | ||
//api.addFiles('angular2-now-tests.js'); | ||
}); |
{ | ||
"name": "angular2-now", | ||
"version": "0.3.5", | ||
"version": "0.3.7", | ||
"description": "Angular 2 component syntax for Angular 1 apps", | ||
@@ -5,0 +5,0 @@ "main": "angular2-now.js", |
@@ -23,3 +23,3 @@ ## Angular 2.0 component syntax using Angular 1 and Babel | ||
- **@View** `({ template: '<div>Inline template</div>', templateUrl: 'pth/to/template.html'})` | ||
- **@Inject** `(['$http', myServiceClass, '$q'])` | ||
- **@Inject** `(['$http', myServiceClass, '$q'])` or `('$http', myServiceClass, '$q') | ||
- **bootstrap** `(app [, config ])` | ||
@@ -49,5 +49,9 @@ - **SetModule** `('my-app', ['angular-meteor'])` | ||
Yes, you can. The angular2-now.js library works with both ES6 (Babel) and plain ES5. ES6 examples are in this README and also in Code Demos, above. For an ES5 usage demo see [Plunker](http://plnkr.co/edit/uxV781?p=preview). | ||
Yes, you can. The angular2-now.js library works with both ES6 (Babel) and plain ES5. | ||
Here is an ES6 example [ES6 Angular2-now](http://plnkr.co/edit/JhHlOr?p=preview). Also, there are examples in this README and in Code Demos, above. | ||
For an ES5 usage demo see [ES5 Agular2-now](http://plnkr.co/edit/uxV781?p=preview). | ||
#### Installation | ||
@@ -54,0 +58,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55537
660
618