geheugen-angular
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -42,3 +42,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.geheugenAngular = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
factory: function factory(values) { | ||
return $injector.instantiate(memo.factory, dependencies.reduce(function (locals, dependency, i) { | ||
return $injector.invoke(memo.factory, undefined, dependencies.reduce(function (locals, dependency, i) { | ||
locals[dependency] = values[i]; | ||
@@ -45,0 +45,0 @@ |
@@ -40,3 +40,3 @@ 'use strict'; | ||
factory: function factory(values) { | ||
return $injector.instantiate(memo.factory, dependencies.reduce(function (locals, dependency, i) { | ||
return $injector.invoke(memo.factory, undefined, dependencies.reduce(function (locals, dependency, i) { | ||
locals[dependency] = values[i]; | ||
@@ -43,0 +43,0 @@ |
{ | ||
"name": "geheugen-angular", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Angular bindings for geheugen", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -46,3 +46,3 @@ # geheugen-angular | ||
Returns an Angular constructor<sup>[1](#note1)</sup> for the resolved value of the memo with the provided name. | ||
Returns an Angular factory<sup>[1](#note1)</sup> for the resolved value of the memo with the provided name. | ||
@@ -73,3 +73,3 @@ The return value of this function is suitable for being used as a dependency of an Angular route, e.g.: | ||
Returns an Angular constructor<sup>[1](#note1)</sup> for the [memo](#memo-instance). | ||
Returns an Angular factory<sup>[1](#note1)</sup> for the [memo](#memo-instance). | ||
@@ -82,3 +82,3 @@ The return value of this function is suitable for being used as the `$get` method of an Angular provider, e.g.: | ||
this.$get = memosProvider('example', | ||
($q, $filter) => $q.resolve($filter('number')('3.1415', 2))); | ||
$filter => $filter('number')('3.1415', 2)); | ||
}); | ||
@@ -115,3 +115,3 @@ ``` | ||
The resolved values of the dependant memos will be available as locals to the Angular constructor<sup>[1](#note1)</sup> | ||
The resolved values of the dependant memos will be available as locals to the Angular factory<sup>[1](#note1)</sup> | ||
provided via `factory`, e.g.: | ||
@@ -122,7 +122,7 @@ | ||
.provider('dependencyMemo', function (memosProvider) { | ||
this.$get = memosProvider('dependency', $q => $q.resolve('3.1415')); | ||
this.$get = memosProvider('dependency', () => '3.1415'); | ||
}) | ||
.provider('exampleMemo', function (memosProvider) { | ||
this.$get = memosProvider('example', { dependencies: [ 'dependency' ] }, | ||
($q, $filter, dependency) => $q.resolve($filter('number')(dependency, 2))); | ||
($filter, dependency) => $filter('number')(dependency, 2)); | ||
}); | ||
@@ -141,7 +141,7 @@ ``` | ||
##### factory | ||
Type: `Function` or `Array` | ||
Type: `Function` or `Array<String|Function>` | ||
The Angular constructor<sup>[1](#note1)</sup> for the resolved value of the memo. | ||
The Angular factory<sup>[1](#note1)</sup> for the resolved value of the memo. | ||
The factory must return a promise for the resolved value. | ||
The factory can return the either resolved value itself or a promise for the resolved value. | ||
@@ -201,4 +201,4 @@ #### memos(name) | ||
<small> | ||
<a name="note1">1</a>: An Angular constructor is any value that can be passed as the `Type` argument to | ||
[`$injector.instantiate()`](https://docs.angularjs.org/api/auto/service/$injector#instantiate). | ||
<a name="note1">1</a>: An Angular factory is any value that can be passed as the `fn` argument to | ||
[`$injector.invoke()`](https://docs.angularjs.org/api/auto/service/$injector#invoke). | ||
</small> |
@@ -24,3 +24,3 @@ import angular from 'angular'; | ||
onReset: memo.opts.onReset !== undefined ? () => $injector.invoke(memo.opts.onReset) : undefined, | ||
factory: values => $injector.instantiate(memo.factory, dependencies.reduce((locals, dependency, i) => { | ||
factory: values => $injector.invoke(memo.factory, undefined, dependencies.reduce((locals, dependency, i) => { | ||
locals[dependency] = values[i]; | ||
@@ -27,0 +27,0 @@ |
@@ -7,16 +7,37 @@ 'use strict'; | ||
describe('memos()', () => { | ||
it('should return the promise for the memo with the provided name', done => { | ||
module(memosProvider => { | ||
// Given | ||
memosProvider('testValue', $q => $q.resolve('Test Value')); | ||
describe('when the factory returns a promise', () => { | ||
it('should return the promise for the memo with the provided name', done => { | ||
module(memosProvider => { | ||
// Given | ||
memosProvider('testValue', $q => $q.resolve('Test Value')); | ||
}); | ||
inject(($rootScope, memos) => { | ||
// When | ||
let testValuePromise = memos('testValue'); | ||
// Then | ||
expect(testValuePromise).to.eventually.equal('Test Value').and.notify(done); | ||
$rootScope.$digest(); | ||
}); | ||
}); | ||
}); | ||
inject(($rootScope, memos) => { | ||
// When | ||
let testValuePromise = memos('testValue'); | ||
describe('when the factory does not return a promise', () => { | ||
it('should return the promise for the memo with the provided name', done => { | ||
module(memosProvider => { | ||
// Given | ||
memosProvider('testValue', () => 'Test Value'); | ||
}); | ||
// Then | ||
expect(testValuePromise).to.eventually.equal('Test Value').and.notify(done); | ||
inject(($rootScope, memos) => { | ||
// When | ||
let testValuePromise = memos('testValue'); | ||
$rootScope.$digest(); | ||
// Then | ||
expect(testValuePromise).to.eventually.equal('Test Value').and.notify(done); | ||
$rootScope.$digest(); | ||
}); | ||
}); | ||
@@ -23,0 +44,0 @@ }); |
Sorry, the diff of this file is not supported yet
55481
701