DS.SnapshotRecordArray Class addon/-private/system/snapshot-record-array.js:5


PRIVATE

Show:

Methods

Properties

Show:

snapshots

Array

Get snapshots of the underlying record array

Example

app/adapters/post.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import DS from 'ember-data'

export default DS.JSONAPIAdapter.extend({
  shouldReloadAll(store, snapshotArray) {
    var snapshots = snapshotArray.snapshots();

    return snapshots.any(function(ticketSnapshot) {
      var timeDiff = moment().diff(ticketSnapshot.attr('lastAccessedAt'), 'minutes');
      if (timeDiff > 20) {
        return true;
      } else {
        return false;
      }
    });
  }
});

Returns:

Array
Array of snapshots
Show:

_recordArray

{Array} private

An array of records

_snapshots

{Array} private

An array of snapshots

adapterOptions

{Object}

A hash of adapter options passed into the store method for this request.

Example

app/adapters/post.js
1
2
3
4
5
6
7
8
9
10
import MyCustomAdapter from './custom-adapter';

export default MyCustomAdapter.extend({
  findAll(store, type, sinceToken, snapshotRecordArray) {
    if (snapshotRecordArray.adapterOptions.subscribe) {
      // ...
    }
    // ...
  }
});

include

{String|Array}

The relationships to include for this request.

Example

app/adapters/application.js
1
2
3
4
5
6
7
8
9
import DS from 'ember-data';

export default DS.Adapter.extend({
  findAll(store, type, snapshotRecordArray) {
    var url = `/${type.modelName}?include=${encodeURIComponent(snapshotRecordArray.include)}`;

    return fetch(url).then((response) => response.json())
  }
});

length

{Number}

Number of records in the array

Example

app/adapters/post.js
1
2
3
4
5
6
7
import DS from 'ember-data'

export default DS.JSONAPIAdapter.extend({
  shouldReloadAll(store, snapshotRecordArray) {
    return !snapshotRecordArray.length;
  },
});

meta

{Object}

Meta objects for the record array.

Example

app/adapters/post.js
1
2
3
4
5
6
7
8
9
import DS from 'ember-data'

export default DS.JSONAPIAdapter.extend({
  shouldReloadAll(store, snapshotRecordArray) {
    var lastRequestTime = snapshotRecordArray.meta.lastRequestTime;
    var twentyMinutes = 20 * 60 * 1000;
    return Date.now() > lastRequestTime + twentyMinutes;
  },
});

type

{DS.Model}

The type of the underlying records for the snapshots in the array, as a DS.Model