Socket
Socket
Sign inDemoInstall

redux-orm

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-orm - npm Package Compare versions

Comparing version 0.1.17 to 0.1.18

22

lib/Model.js

@@ -423,7 +423,11 @@ 'use strict';

value: function nextId() {
var idArr = this.accessIds();
if (idArr.length === 0) {
return 0;
if (typeof this._sessionCache.nextId === 'undefined') {
var idArr = this.accessIds();
if (idArr.length === 0) {
this._sessionCache.nextId = 0;
} else {
this._sessionCache.nextId = Math.max.apply(Math, _toConsumableArray(idArr)) + 1;
}
}
return Math.max.apply(Math, _toConsumableArray(idArr)) + 1;
return this._sessionCache.nextId;
}

@@ -470,4 +474,12 @@ }, {

var props = Object.assign({}, userProps);
if (!props.hasOwnProperty(idAttribute)) {
props[idAttribute] = this.nextId();
var nextId = this.nextId();
props[idAttribute] = nextId;
this._sessionCache.nextId++;
} else {
var id = props[idAttribute];
if (id > this.nextId()) {
this._sessionCache.nextId = id + 1;
}
}

@@ -474,0 +486,0 @@

@@ -118,3 +118,2 @@ 'use strict';

this.updates = [];
var nextState = {};

@@ -127,3 +126,3 @@ var currentAction = this.action;

// The remaining updates are for M2M tables.
return this.updates.reduce(function (state, action) {
var finalState = this.updates.reduce(function (state, action) {
var modelName = action.meta.name;

@@ -133,2 +132,5 @@ state[modelName] = _this2[modelName].getNextState();

}, nextState);
this.updates = [];
return finalState;
}

@@ -135,0 +137,0 @@ }]);

@@ -457,8 +457,18 @@ 'use strict';

Genre.create({ name: 'Fiction' });
Genre.create({ name: 'Non-Fiction' });
Genre.create({ name: 'Business' });
var g1 = Genre.create({ name: 'Fiction' });
var g2 = Genre.create({ name: 'Non-Fiction' });
var g3 = Genre.create({ name: 'Business' });
var book = Book.create({ name: 'A Phenomenal Novel', genres: [0, 1] });
Book.create({ name: 'Not so good Novel', genres: [] });
(0, _chai.expect)(initialState.BookGenres.items).to.have.length(2);
(0, _chai.expect)(book._fields.genres).to.be.undefined;
var session = schema.from(initialState);
Book = session.Book;
Genre = session.Genre;
Book.withId(1).genres.add(1, g3);
var nextState = session.reduce();
(0, _chai.expect)(nextState.BookGenres.items).to.have.length(4);
(0, _chai.expect)(nextState.BookGenres.items).to.deep.equal([0, 1, 2, 3]);
});

@@ -465,0 +475,0 @@

{
"name": "redux-orm",
"version": "0.1.17",
"version": "0.1.18",
"description": "Simple ORM to manage and query your state trees",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -267,7 +267,11 @@ import forOwn from 'lodash/object/forOwn';

static nextId() {
const idArr = this.accessIds();
if (idArr.length === 0) {
return 0;
if (typeof this._sessionCache.nextId === 'undefined') {
const idArr = this.accessIds();
if (idArr.length === 0) {
this._sessionCache.nextId = 0;
} else {
this._sessionCache.nextId = Math.max(...idArr) + 1;
}
}
return Math.max(...idArr) + 1;
return this._sessionCache.nextId;
}

@@ -312,4 +316,12 @@

const props = Object.assign({}, userProps);
if (!props.hasOwnProperty(idAttribute)) {
props[idAttribute] = this.nextId();
const nextId = this.nextId();
props[idAttribute] = nextId;
this._sessionCache.nextId++;
} else {
const id = props[idAttribute];
if (id > this.nextId()) {
this._sessionCache.nextId = id + 1;
}
}

@@ -316,0 +328,0 @@

@@ -85,3 +85,2 @@ import partition from 'lodash/collection/partition';

reduce() {
this.updates = [];
const nextState = {};

@@ -95,3 +94,3 @@ const currentAction = this.action;

// The remaining updates are for M2M tables.
return this.updates.reduce((state, action) => {
const finalState = this.updates.reduce((state, action) => {
const modelName = action.meta.name;

@@ -101,2 +100,5 @@ state[modelName] = this[modelName].getNextState();

}, nextState);
this.updates = [];
return finalState;
}

@@ -103,0 +105,0 @@ };

@@ -302,10 +302,20 @@ import {expect} from 'chai';

const initialState = schema.getDefaultState();
const {Book, Genre} = schema.withMutations(initialState);
let {Book, Genre} = schema.withMutations(initialState);
Genre.create({name: 'Fiction'});
Genre.create({name: 'Non-Fiction'});
Genre.create({name: 'Business'});
const g1 = Genre.create({name: 'Fiction'});
const g2 = Genre.create({name: 'Non-Fiction'});
const g3 = Genre.create({name: 'Business'});
const book = Book.create({name: 'A Phenomenal Novel', genres: [0, 1]});
Book.create({name: 'Not so good Novel', genres: []});
expect(initialState.BookGenres.items).to.have.length(2);
expect(book._fields.genres).to.be.undefined;
const session = schema.from(initialState);
Book = session.Book;
Genre = session.Genre;
Book.withId(1).genres.add(1, g3);
const nextState = session.reduce();
expect(nextState.BookGenres.items).to.have.length(4);
expect(nextState.BookGenres.items).to.deep.equal([0, 1, 2, 3]);
});

@@ -312,0 +322,0 @@

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

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

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

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

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