geheugen-angular
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -52,14 +52,18 @@ (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){ | ||
var memo = function memo() { | ||
return Object.defineProperties(function () { | ||
return $memo.resolve(); | ||
}; | ||
memo.reset = function () { | ||
return $memo.reset(); | ||
}; | ||
memo.resetDependants = function () { | ||
return $memo.resetDependants(); | ||
}; | ||
return memo; | ||
}, Object.assign({}, opts.properties, { | ||
get: { value: function value() { | ||
return $memo.get(); | ||
} }, | ||
set: { value: function value(_value) { | ||
return $memo.set(_value); | ||
} }, | ||
reset: { value: function value() { | ||
return $memo.reset(); | ||
} }, | ||
resetDependants: { value: function value() { | ||
return $memo.resetDependants(); | ||
} } | ||
})); | ||
}]; | ||
@@ -69,14 +73,18 @@ }; | ||
memosProvider.$get = ['$q', '$injector', function ($q, $injector) { | ||
var memos = function memos(name) { | ||
return Object.defineProperties(function (name) { | ||
return ensureMemo($q, $injector, name).resolve(); | ||
}; | ||
memos.reset = function (name) { | ||
return ensureMemo($q, $injector, name).reset(); | ||
}; | ||
memos.resetDependants = function (name) { | ||
return ensureMemo($q, $injector, name).resetDependants(); | ||
}; | ||
return memos; | ||
}, { | ||
get: { value: function value(name) { | ||
return ensureMemo($q, $injector, name).get(); | ||
} }, | ||
set: { value: function value(name, _value2) { | ||
return ensureMemo($q, $injector, name).set(_value2); | ||
} }, | ||
reset: { value: function value(name) { | ||
return ensureMemo($q, $injector, name).reset(); | ||
} }, | ||
resetDependants: { value: function value(name) { | ||
return ensureMemo($q, $injector, name).resetDependants(); | ||
} } | ||
}); | ||
}]; | ||
@@ -119,2 +127,5 @@ | ||
}), | ||
onSet: opts.onSet !== undefined ? function (value) { | ||
return $injector.invoke(opts.onSet, undefined, { value: value }); | ||
} : undefined, | ||
onReset: opts.onReset !== undefined ? function () { | ||
@@ -160,2 +171,4 @@ return $injector.invoke(opts.onReset); | ||
var dependencies = _ref$dependencies === undefined ? [] : _ref$dependencies; | ||
var _ref$onSet = _ref.onSet; | ||
var onSet = _ref$onSet === undefined ? function () {} : _ref$onSet; | ||
var _ref$onReset = _ref.onReset; | ||
@@ -174,3 +187,3 @@ var onReset = _ref$onReset === undefined ? function () {} : _ref$onReset; | ||
return Object.assign(this, { Q: Q, singleton: singleton, dependencies: dependencies, onReset: onReset, factory: factory, promise: promise, value: value, dependants: [] }); | ||
return Object.assign(this, { Q: Q, singleton: singleton, dependencies: dependencies, onSet: onSet, onReset: onReset, factory: factory, promise: promise, value: value, dependants: [] }); | ||
} | ||
@@ -202,2 +215,16 @@ | ||
}, { | ||
key: "get", | ||
value: function get() { | ||
return this.value; | ||
} | ||
}, { | ||
key: "set", | ||
value: function set(value) { | ||
this.resetDependants(); | ||
this.onSet(value); | ||
this.value = value; | ||
} | ||
}, { | ||
key: "reset", | ||
@@ -234,3 +261,3 @@ value: function reset() { | ||
Object.keys(_Memo).forEach(function (key) { | ||
if (key === "default") return; | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
@@ -237,0 +264,0 @@ enumerable: true, |
@@ -50,14 +50,18 @@ 'use strict'; | ||
var memo = function memo() { | ||
return Object.defineProperties(function () { | ||
return $memo.resolve(); | ||
}; | ||
memo.reset = function () { | ||
return $memo.reset(); | ||
}; | ||
memo.resetDependants = function () { | ||
return $memo.resetDependants(); | ||
}; | ||
return memo; | ||
}, Object.assign({}, opts.properties, { | ||
get: { value: function value() { | ||
return $memo.get(); | ||
} }, | ||
set: { value: function value(_value) { | ||
return $memo.set(_value); | ||
} }, | ||
reset: { value: function value() { | ||
return $memo.reset(); | ||
} }, | ||
resetDependants: { value: function value() { | ||
return $memo.resetDependants(); | ||
} } | ||
})); | ||
}]; | ||
@@ -67,14 +71,18 @@ }; | ||
memosProvider.$get = ['$q', '$injector', function ($q, $injector) { | ||
var memos = function memos(name) { | ||
return Object.defineProperties(function (name) { | ||
return ensureMemo($q, $injector, name).resolve(); | ||
}; | ||
memos.reset = function (name) { | ||
return ensureMemo($q, $injector, name).reset(); | ||
}; | ||
memos.resetDependants = function (name) { | ||
return ensureMemo($q, $injector, name).resetDependants(); | ||
}; | ||
return memos; | ||
}, { | ||
get: { value: function value(name) { | ||
return ensureMemo($q, $injector, name).get(); | ||
} }, | ||
set: { value: function value(name, _value2) { | ||
return ensureMemo($q, $injector, name).set(_value2); | ||
} }, | ||
reset: { value: function value(name) { | ||
return ensureMemo($q, $injector, name).reset(); | ||
} }, | ||
resetDependants: { value: function value(name) { | ||
return ensureMemo($q, $injector, name).resetDependants(); | ||
} } | ||
}); | ||
}]; | ||
@@ -117,2 +125,5 @@ | ||
}), | ||
onSet: opts.onSet !== undefined ? function (value) { | ||
return $injector.invoke(opts.onSet, undefined, { value: value }); | ||
} : undefined, | ||
onReset: opts.onReset !== undefined ? function () { | ||
@@ -119,0 +130,0 @@ return $injector.invoke(opts.onReset); |
{ | ||
"name": "geheugen-angular", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Angular bindings for geheugen", | ||
@@ -30,5 +30,5 @@ "main": "lib/index.js", | ||
"angular-mocks": "^1.5.8", | ||
"babel-core": "^6.13.0", | ||
"babel-core": "^6.13.2", | ||
"babel-polyfill": "^6.13.0", | ||
"babel-preset-es2015": "^6.13.0", | ||
"babel-preset-es2015": "^6.13.2", | ||
"babel-preset-es2016": "^6.11.3", | ||
@@ -41,6 +41,6 @@ "babel-preset-stage-3": "^6.11.0", | ||
"chokidar": "^1.6.0", | ||
"del": "^2.2.1", | ||
"eslint": "^3.2.2", | ||
"del": "^2.2.2", | ||
"eslint": "^3.3.1", | ||
"exposify": "^0.5.0", | ||
"geheugen": "^1.4.0", | ||
"geheugen": "^1.5.0", | ||
"gulp": "^3.9.1", | ||
@@ -51,3 +51,3 @@ "gulp-babel": "^6.1.2", | ||
"gulp-util": "^3.0.7", | ||
"karma": "^1.1.2", | ||
"karma": "^1.2.0", | ||
"karma-babel-preprocessor": "^6.0.1", | ||
@@ -64,5 +64,5 @@ "karma-chai": "^0.1.0", | ||
"karma-sinon": "^1.0.5", | ||
"mocha": "^3.0.1", | ||
"mocha": "^3.0.2", | ||
"phantomjs-polyfill": "0.0.2", | ||
"phantomjs-prebuilt": "^2.1.10", | ||
"phantomjs-prebuilt": "^2.1.12", | ||
"sinon": "^1.17.5", | ||
@@ -69,0 +69,0 @@ "sinon-chai": "^2.8.0", |
@@ -96,2 +96,11 @@ # geheugen-angular | ||
###### properties | ||
Type: `Object<String, Object>` | ||
The memo properties. | ||
These properties will be defined on the memo via [`Object.defineProperties()`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties). | ||
Properties with the names `get`, `set`, `reset`, and `resetDependants` will be ignored. | ||
###### singleton | ||
@@ -127,2 +136,13 @@ Type: `Boolean` | ||
###### onSet | ||
Type: `Function` | ||
The set event handler. | ||
This function will be invoked when the memo is set. | ||
This function will be invoked via [`$injector.invoke()`](https://docs.angularjs.org/api/auto/service/$injector#invoke). | ||
The value of the memo will be available as the `value` local to this function. | ||
###### onReset | ||
@@ -154,2 +174,27 @@ Type: `Function` | ||
##### memos.get(name) | ||
Type: `Function` | ||
Return the value of the memo with the provided name. | ||
###### name | ||
Type: `String` | ||
The name of the memo. | ||
##### memos.set(name, value) | ||
Type: `Function` | ||
Update the value of the memo with the provided name. | ||
###### name | ||
Type: `String` | ||
The name of the memo. | ||
###### value | ||
Type: `?` | ||
The value. | ||
##### memos.reset(name) | ||
@@ -185,2 +230,17 @@ Type: `Function` | ||
##### memo.get() | ||
Type: `Function` | ||
Return the value of the memo. | ||
##### memo.set(value) | ||
Type: `Function` | ||
Update the value of the memo. | ||
###### value | ||
Type: `?` | ||
The value. | ||
##### memo.reset() | ||
@@ -187,0 +247,0 @@ Type: `Function` |
@@ -26,8 +26,8 @@ import angular from 'angular'; | ||
let memo = () => $memo.resolve(); | ||
memo.reset = () => $memo.reset(); | ||
memo.resetDependants = () => $memo.resetDependants(); | ||
return memo; | ||
return Object.defineProperties(() => $memo.resolve(), Object.assign({}, opts.properties, { | ||
get: { value: () => $memo.get() }, | ||
set: { value: (value) => $memo.set(value) }, | ||
reset: { value: () => $memo.reset() }, | ||
resetDependants: { value: () => $memo.resetDependants() } | ||
})); | ||
}]; | ||
@@ -37,8 +37,8 @@ }; | ||
memosProvider.$get = ['$q', '$injector', ($q, $injector) => { | ||
let memos = name => ensureMemo($q, $injector, name).resolve(); | ||
memos.reset = name => ensureMemo($q, $injector, name).reset(); | ||
memos.resetDependants = name => ensureMemo($q, $injector, name).resetDependants(); | ||
return memos; | ||
return Object.defineProperties(name => ensureMemo($q, $injector, name).resolve(), { | ||
get: { value: name => ensureMemo($q, $injector, name).get() }, | ||
set: { value: (name, value) => ensureMemo($q, $injector, name).set(value) }, | ||
reset: { value: name => ensureMemo($q, $injector, name).reset() }, | ||
resetDependants: { value: name => ensureMemo($q, $injector, name).resetDependants() } | ||
}); | ||
}]; | ||
@@ -74,2 +74,3 @@ | ||
dependencies: dependencies.map(dependency => ensureMemo($q, $injector, dependency, nextContext)), | ||
onSet: opts.onSet !== undefined ? value => $injector.invoke(opts.onSet, undefined, { value }) : undefined, | ||
onReset: opts.onReset !== undefined ? () => $injector.invoke(opts.onReset) : undefined, | ||
@@ -76,0 +77,0 @@ factory: values => $injector.invoke(factory, undefined, dependencies.reduce((locals, dependency, i) => { |
@@ -7,3 +7,3 @@ 'use strict'; | ||
describe('when the factory returns a promise', () => { | ||
context('when the factory returns a promise', () => { | ||
it('should throw an error if there is no memo with the provided name', inject(memos => { | ||
@@ -37,3 +37,3 @@ // Given | ||
describe('when the factory does not return a promise', () => { | ||
context('when the factory does not return a promise', () => { | ||
it('should return the promise for the memo with the provided name', done => { | ||
@@ -57,2 +57,56 @@ module(memosProvider => { | ||
describe('get()', () => { | ||
it('should return the value of the memo with the provided name', done => { | ||
let testValueMemoGetFn; | ||
module(memosProvider => { | ||
testValueMemoGetFn = memosProvider('testValue', $q => $q.resolve('Test Value')); | ||
}); | ||
inject(($injector, $rootScope, memos) => { | ||
// Given | ||
let testValueMemo = $injector.instantiate(testValueMemoGetFn); | ||
testValueMemo(); | ||
$rootScope.$digest(); | ||
// When | ||
let value = memos.get('testValue'); | ||
// Then | ||
expect(value).to.equal('Test Value'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('set()', () => { | ||
it('should update the value of the memo with the provided name', done => { | ||
let testValueMemoGetFn; | ||
module(memosProvider => { | ||
testValueMemoGetFn = memosProvider('testValue', $q => $q.resolve('Test Value')); | ||
}); | ||
inject(($injector, $rootScope, memos) => { | ||
// Given | ||
let testValueMemo = $injector.instantiate(testValueMemoGetFn); | ||
testValueMemo(); | ||
$rootScope.$digest(); | ||
// When | ||
memos.set('testValue', 'New Test Value'); | ||
// Then | ||
expect(testValueMemo()).to.eventually.equal('New Test Value').and.notify(done); | ||
$rootScope.$digest(); | ||
}); | ||
}); | ||
}); | ||
describe('reset()', () => { | ||
@@ -59,0 +113,0 @@ it('should reset the memo with the provided name', done => { |
@@ -98,2 +98,56 @@ 'use strict'; | ||
describe('get()', () => { | ||
it('should return the value of the memo', done => { | ||
let testValueMemoGetFn; | ||
module(memosProvider => { | ||
testValueMemoGetFn = memosProvider('testValue', $q => $q.resolve('Test Value')); | ||
}); | ||
inject(($injector, $rootScope) => { | ||
// Given | ||
let testValueMemo = $injector.instantiate(testValueMemoGetFn); | ||
testValueMemo(); | ||
$rootScope.$digest(); | ||
// When | ||
let value = testValueMemo.get(); | ||
// Then | ||
expect(value).to.equal('Test Value'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('set()', () => { | ||
it('should update the value of the memo', done => { | ||
let testValueMemoGetFn; | ||
module(memosProvider => { | ||
testValueMemoGetFn = memosProvider('testValue', $q => $q.resolve('Test Value')); | ||
}); | ||
inject(($injector, $rootScope) => { | ||
// Given | ||
let testValueMemo = $injector.instantiate(testValueMemoGetFn); | ||
testValueMemo(); | ||
$rootScope.$digest(); | ||
// When | ||
testValueMemo.set('New Test Value'); | ||
// Then | ||
expect(testValueMemo()).to.eventually.equal('New Test Value').and.notify(done); | ||
$rootScope.$digest(); | ||
}); | ||
}); | ||
}); | ||
describe('reset()', () => { | ||
@@ -152,2 +206,25 @@ it('should reset the memo', done => { | ||
context('when the properties option is set', () => { | ||
it('should provide a memo with the properties defined', done => { | ||
let testValueMemoGetFn; | ||
module(memosProvider => { | ||
// Given | ||
let properties = { testProperty: { value: 'Test Property Value' } }; | ||
testValueMemoGetFn = memosProvider('testValue', { properties }, $q => $q.resolve('Test Value')); | ||
}); | ||
inject($injector => { | ||
// When | ||
let testValueMemo = $injector.instantiate(testValueMemoGetFn); | ||
// Then | ||
expect(testValueMemo.testProperty).to.equal('Test Property Value'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
context('when the singleton option is set', () => { | ||
@@ -201,2 +278,56 @@ it('should provide a singleton memo', done => { | ||
describe('get()', () => { | ||
it('should return the value of the memo', done => { | ||
let testValueMemoGetFn; | ||
module(memosProvider => { | ||
testValueMemoGetFn = memosProvider('testValue', { singleton: true }, $q => $q.resolve('Test Value')); | ||
}); | ||
inject(($injector, $rootScope) => { | ||
// Given | ||
let testValueMemo = $injector.instantiate(testValueMemoGetFn); | ||
testValueMemo(); | ||
$rootScope.$digest(); | ||
// When | ||
let value = testValueMemo.get(); | ||
// Then | ||
expect(value).to.equal('Test Value'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('set()', () => { | ||
it('should update the value of the memo', done => { | ||
let testValueMemoGetFn; | ||
module(memosProvider => { | ||
testValueMemoGetFn = memosProvider('testValue', { singleton: true }, $q => $q.resolve('Test Value')); | ||
}); | ||
inject(($injector, $rootScope) => { | ||
// Given | ||
let testValueMemo = $injector.instantiate(testValueMemoGetFn); | ||
testValueMemo(); | ||
$rootScope.$digest(); | ||
// When | ||
testValueMemo.set('New Test Value'); | ||
// Then | ||
expect(testValueMemo()).to.eventually.equal('New Test Value').and.notify(done); | ||
$rootScope.$digest(); | ||
}); | ||
}); | ||
}); | ||
describe('reset()', () => { | ||
@@ -261,4 +392,55 @@ it('should reset the memo', done => { | ||
}); | ||
describe('get()', () => { | ||
it('should return the value of the memo', done => { | ||
let testValueMemoGetFn; | ||
module(memosProvider => { | ||
testValueMemoGetFn = memosProvider('testValue', { singleton: false }, $q => $q.resolve('Test Value')); | ||
}); | ||
inject(($injector, $rootScope) => { | ||
// Given | ||
let testValueMemo = $injector.instantiate(testValueMemoGetFn); | ||
testValueMemo(); | ||
$rootScope.$digest(); | ||
// When | ||
let value = testValueMemo.get(); | ||
// Then | ||
expect(value).to.equal('Test Value'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
context('when the onSet function option is provided', () => { | ||
describe('set()', () => { | ||
it('should invoke the onSet function', () => { | ||
let testOnSet, testValueMemoGetFn; | ||
module(memosProvider => { | ||
testOnSet = sinon.spy(); | ||
testValueMemoGetFn = memosProvider('testValue', { onSet: [ 'value', testOnSet ] }, $q => $q.resolve('Test Value')); | ||
}); | ||
inject($injector => { | ||
// Given | ||
let testValueMemo = $injector.instantiate(testValueMemoGetFn); | ||
// When | ||
testValueMemo.set('New Test Value'); | ||
// Then | ||
expect(testOnSet).to.have.been.calledWith('New Test Value'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
context('when the onReset function option is provided', () => { | ||
@@ -348,2 +530,35 @@ describe('reset()', () => { | ||
describe('set()', () => { | ||
it('should reset the dependants of the memo', done => { | ||
let testValue, testDependencyMemoGetFn, testValueMemoGetFn; | ||
module(memosProvider => { | ||
testValue = 'Test Value'; | ||
testDependencyMemoGetFn = memosProvider('testDependency', $q => $q.resolve('Test Dependency')); | ||
testValueMemoGetFn = memosProvider('testValue', { dependencies: [ 'testDependency' ] }, $q => $q.resolve(testValue)); | ||
}); | ||
inject(($injector, $rootScope) => { | ||
// Given | ||
let testDependencyMemo = $injector.instantiate(testDependencyMemoGetFn); | ||
let testValueMemo = $injector.instantiate(testValueMemoGetFn); | ||
testValueMemo(); | ||
$rootScope.$digest(); | ||
// When | ||
testValue = 'New Test Value'; | ||
testDependencyMemo.set('New Test Dependency'); | ||
// Then | ||
expect(testValueMemo()).to.eventually.equal('New Test Value').and.notify(done); | ||
$rootScope.$digest(); | ||
}); | ||
}); | ||
}); | ||
describe('reset()', () => { | ||
@@ -350,0 +565,0 @@ it('should reset the dependants of the memo', done => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
74731
989
257
11