Skip to content

Commit

Permalink
return a promise for findAll unless fromServer is explicitly false (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
jondayton authored Jul 23, 2020
1 parent f3a3542 commit 5fa2a95
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion dist/mobx-async-store.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ function () {

if (records.length > 0) {
// Return data
return records;
return Promise.resolve(records);
} else {
// Otherwise fetch it from the server
return _this.fetchAll(type, queryParams);
Expand Down
2 changes: 1 addition & 1 deletion dist/mobx-async-store.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,7 @@ function () {

if (records.length > 0) {
// Return data
return records;
return Promise.resolve(records);
} else {
// Otherwise fetch it from the server
return _this.fetchAll(type, queryParams);
Expand Down
2 changes: 1 addition & 1 deletion docs/classes/Model.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 1.5.0</em>
<em>API Docs for: 2.0.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion docs/classes/RelatedRecordsArray.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 1.5.0</em>
<em>API Docs for: 2.0.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion docs/classes/Schema.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 1.5.0</em>
<em>API Docs for: 2.0.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion docs/classes/Store.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 1.5.0</em>
<em>API Docs for: 2.0.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion docs/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "mobx-async-store",
"description": "Asyc Data Store for mobx",
"url": "https://github.com/artemis-ag/mobx-async-store",
"version": "1.5.0"
"version": "2.0.0"
},
"files": {
"src/decorators/attributes.js": {
Expand Down
2 changes: 1 addition & 1 deletion docs/files/src_Model.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 1.5.0</em>
<em>API Docs for: 2.0.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
4 changes: 2 additions & 2 deletions docs/files/src_Store.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 1.5.0</em>
<em>API Docs for: 2.0.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down Expand Up @@ -504,7 +504,7 @@ <h1 class="file-heading">File: src/Store.js</h1>

if (records.length &gt; 0) {
// Return data
return records
return Promise.resolve(records)
} else {
// Otherwise fetch it from the server
return this.fetchAll(type, queryParams)
Expand Down
2 changes: 1 addition & 1 deletion docs/files/src_decorators_attributes.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 1.5.0</em>
<em>API Docs for: 2.0.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion docs/files/src_decorators_relationships.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 1.5.0</em>
<em>API Docs for: 2.0.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion docs/files/src_schema.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 1.5.0</em>
<em>API Docs for: 2.0.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion docs/files/src_utils.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 1.5.0</em>
<em>API Docs for: 2.0.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="./assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 1.5.0</em>
<em>API Docs for: 2.0.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@artemisag/mobx-async-store",
"version": "1.5.0",
"version": "2.0.0",
"module": "dist/mobx-async-store.esm.js",
"browser": "dist/mobx-async-store.cjs.js",
"main": "dist/mobx-async-store.cjs.js",
Expand Down
12 changes: 8 additions & 4 deletions spec/Store.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('Store', () => {
const examples = store.add('todos', exampleData)
expect(examples).toHaveLength(2)

const foundExamples = store.findAll('todos', exampleData, { fromServer: false })
const foundExamples = store.findAll('todos', { fromServer: false })
expect(foundExamples).toHaveLength(2)
})
})
Expand Down Expand Up @@ -512,17 +512,21 @@ describe('Store', () => {

describe('if a query is made with identical params', () => {
it('skips fetch and returns local data from the store', async () => {
expect.assertions(4)
expect.assertions(6)
// Query params for both requests
const queryParams = { filter: { overdue: true } }
// Only need to mock response once :)
fetch.mockResponse(mockTodosResponse)
// Fetch todos
let todos = await store.findAll('todos', { queryParams })
let query = store.findAll('todos', { queryParams })
expect(query).toBeInstanceOf(Promise)
let todos = await query
expect(todos).toHaveLength(1)
expect(fetch.mock.calls).toHaveLength(1)
// Find todos a second time
todos = await store.findAll('todos', { queryParams })
query = store.findAll('todos', { queryParams })
expect(query).toBeInstanceOf(Promise)
todos = await query
// Not fetch should be kicked off
expect(todos).toHaveLength(1)
expect(fetch.mock.calls).toHaveLength(1)
Expand Down
2 changes: 1 addition & 1 deletion src/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ class Store {

if (records.length > 0) {
// Return data
return records
return Promise.resolve(records)
} else {
// Otherwise fetch it from the server
return this.fetchAll(type, queryParams)
Expand Down

0 comments on commit 5fa2a95

Please sign in to comment.