New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

geheugen

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geheugen - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

.eslintrc.js

20

dist/geheugen.js

@@ -24,2 +24,4 @@ (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.geheugen = 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 dependencies = _ref$dependencies === undefined ? [] : _ref$dependencies;
var _ref$onSet = _ref.onSet;
var onSet = _ref$onSet === undefined ? function () {} : _ref$onSet;
var _ref$onReset = _ref.onReset;

@@ -38,3 +40,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: [] });
}

@@ -66,2 +68,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",

@@ -98,3 +114,3 @@ value: function reset() {

Object.keys(_Memo).forEach(function (key) {
if (key === "default") return;
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {

@@ -101,0 +117,0 @@ enumerable: true,

2

lib/index.js

@@ -10,3 +10,3 @@ 'use strict';

Object.keys(_Memo).forEach(function (key) {
if (key === "default") return;
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {

@@ -13,0 +13,0 @@ enumerable: true,

@@ -23,2 +23,4 @@ "use strict";

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;

@@ -37,3 +39,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: [] });
}

@@ -65,2 +67,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",

@@ -67,0 +83,0 @@ value: function reset() {

{
"name": "geheugen",
"version": "1.4.0",
"version": "1.5.0",
"description": "A memoisation toolkit",

@@ -27,24 +27,27 @@ "main": "lib/index.js",

},
"engines": {
"node": ">=4"
},
"devDependencies": {
"babel-core": "^6.7.2",
"babel-polyfill": "^6.7.2",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-3": "^6.5.0",
"browserify": "^13.0.0",
"babel-core": "^6.13.2",
"babel-polyfill": "^6.13.0",
"babel-preset-es2015": "^6.13.2",
"babel-preset-es2016": "^6.11.3",
"babel-preset-stage-3": "^6.11.0",
"browserify": "^13.1.0",
"chai": "^3.5.0",
"chai-as-promised": "^5.3.0",
"chalk": "^1.1.1",
"chokidar": "^1.4.3",
"del": "^2.2.0",
"chalk": "^1.1.3",
"chokidar": "^1.6.0",
"del": "^2.2.2",
"eslint": "^3.3.1",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-jshint": "^2.0.0",
"gulp-mocha": "^2.2.0",
"gulp-eslint": "^3.0.1",
"gulp-mocha": "^3.0.1",
"gulp-sourcemaps": "^1.6.0",
"gulp-util": "^3.0.7",
"jshint": "^2.9.1",
"jshint-stylish": "^2.1.0",
"mocha-sinon": "^1.1.5",
"mocha": "^3.0.2",
"promise.prototype.finally": "^1.0.1",
"sinon": "^1.17.3",
"sinon": "^1.17.5",
"sinon-chai": "^2.8.0",

@@ -55,4 +58,4 @@ "vinyl-buffer": "^1.0.0",

"peerDependencies": {
"babel-polyfill": "^6.7.2"
"babel-polyfill": "^6.13.0"
}
}

@@ -71,3 +71,3 @@ # geheugen

##### new Memo({ Q, singleton, dependencies, onReset factory, promise, value })
##### new Memo({ Q, singleton, dependencies, onSet, onReset factory, promise, value })

@@ -103,2 +103,11 @@ ###### Q

###### onSet
Type: `Function`
Default: `(value) => {}`
The set event handler.
The set event handler will be invoked when the `set()` method is invoked.
###### onReset

@@ -154,2 +163,12 @@ Type: `Function`

##### get()
Return the value the the memo.
##### set()
Update the value of the memo.
Any memo that has specified this memo as a dependency will be reset.
##### reset()

@@ -184,2 +203,7 @@

###### onSet
Type: `Function`
The set event handler.
###### onReset

@@ -186,0 +210,0 @@ Type: `Function`

@@ -6,2 +6,3 @@ export class Memo {

dependencies = [],
onSet = () => {},
onReset = () => {},

@@ -16,3 +17,3 @@ factory = () => {},

return Object.assign(this, { Q, singleton, dependencies, onReset, factory, promise, value, dependants: [] });
return Object.assign(this, { Q, singleton, dependencies, onSet, onReset, factory, promise, value, dependants: [] });
}

@@ -43,2 +44,14 @@

get() {
return this.value;
}
set(value) {
this.resetDependants();
this.onSet(value);
this.value = value;
}
reset() {

@@ -45,0 +58,0 @@ this.resetDependants();

@@ -1,3 +0,1 @@

import sinon from 'sinon';
import { Memo } from './Memo.js';

@@ -12,2 +10,3 @@

let dependencies = [];
let onSet = (value) => {};
let onReset = () => {};

@@ -19,3 +18,3 @@ let factory = () => {};

// When
let memo = new Memo({ Q, singleton, dependencies, onReset, factory, promise, value });
let memo = new Memo({ Q, singleton, dependencies, onSet, onReset, factory, promise, value });

@@ -26,2 +25,3 @@ // Then

expect(memo.dependencies).to.equal(dependencies);
expect(memo.onSet).to.equal(onSet);
expect(memo.onReset).to.equal(onReset);

@@ -36,3 +36,3 @@ expect(memo.factory).to.equal(factory);

describe('resolve()', () => {
describe('when the memo has no dependencies', () => {
context('when the memo has no dependencies', () => {
it('should invoke the factory with no arguments', () => {

@@ -53,3 +53,3 @@ // Given

describe('when the memo has dependencies', () => {
context('when the memo has dependencies', () => {
it('should invoke the factory with the resolved values of the dependencies', () => {

@@ -95,3 +95,3 @@ // Given

describe('when the promise succeeds', () => {
context('when the promise succeeds', () => {
it('should store the value of the promise', () => {

@@ -124,3 +124,3 @@ // Given

describe('when the promise fails', () => {
context('when the promise fails', () => {
it('should remove the promise', () => {

@@ -139,3 +139,3 @@ // Given

describe('when the memo has a promise', () => {
context('when the memo has a promise', () => {
it('should return the promise', () => {

@@ -154,4 +154,4 @@ // Given

describe('when the memo has a value', () => {
describe('when the singleton flag is not set', () => {
context('when the memo has a value', () => {
context('when the singleton flag is not set', () => {
it('should return a promise via the factory', () => {

@@ -171,3 +171,3 @@ // Given

describe('when the singleton flag is set', () => {
context('when the singleton flag is set', () => {
it('should return a promise resolved with the value', () => {

@@ -189,4 +189,67 @@ // Given

describe('get()', () => {
it('should return the value', () => {
// Given
let memo = new Memo();
memo.value = 'Test Memo Value';
// When
let value = memo.get();
// Then
expect(value).to.equal('Test Memo Value');
});
});
describe('set()', () => {
context('when the memo has dependants', () => {
it('should reset the dependants', () => {
// Given
let memo = new Memo();
let dependants = [ 1, 2, 3 ].map(n => {
let dependant = new Memo({ dependencies: [ memo ] });
sinon.spy(dependant, 'reset');
return dependant;
});
// When
memo.set('Test Memo Value');
// Then
dependants.forEach(dependant => {
expect(dependant.reset).to.have.been.called;
});
});
});
it('should invoke the set event handler with the value', () => {
// Given
let memo = new Memo();
sinon.spy(memo, 'onSet');
// When
memo.set('Test Memo Value');
// Then
expect(memo.onSet).to.have.been.calledWith('Test Memo Value');
});
it('should update the value', () => {
// Given
let memo = new Memo();
// When
memo.set('Test Memo Value');
// Then
expect(memo.value).to.equal('Test Memo Value');
});
});
describe('reset()', () => {
describe('when the memo has dependants', () => {
context('when the memo has dependants', () => {
it('should reset the dependants', () => {

@@ -193,0 +256,0 @@ // Given

@@ -1,3 +0,1 @@

'use strict';
import 'babel-polyfill';

@@ -4,0 +2,0 @@ import 'promise.prototype.finally';

@@ -1,3 +0,11 @@

import mochaSinon from 'mocha-sinon';
import sinon from 'sinon';
mochaSinon();
beforeEach(() => {
global.sinon = sinon.sandbox.create();
});
afterEach(() => {
global.sinon.restore();
delete global.sinon;
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc