How to use the js-data.DataStore function in js-data

To help you get started, we’ve selected a few js-data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Wikodit / js-data-jsonapi-light / test / ds.ts View on Github external
import { DataStore } from 'js-data'

declare var JSData:any;
declare var JSDataJsonApiLight:any;

export const store = new DataStore({
  // addToCache: JSDataJsonApiLight.JSDataOverride.addToCache,
  // mapperWrap: JSDataJsonApiLight.JSDataOverride.mapperWrap
});

const jsonApiAdapter = new JSDataJsonApiLight.JsonApiAdapter({
  suffix: '.json',
  basePath: 'api',
  store: store
});

store.registerAdapter('jsonApi', jsonApiAdapter, { default: true })

// afterEach(function(){
//   DS.clear()
// })
github js-data / js-data-http / build_examples / webpack_es6 / app.js View on Github external
import {DataStore} from 'js-data'
// normally this would be "import DSHttpAdatper from 'js-data-http'"
import HttpAdapter from '../../';

document.getElementById('main').innerHTML = HttpAdapter.version.full;

var adapter = new HttpAdapter()
var store = new DataStore()
store.registerAdapter('http', adapter, { default: true })
store.defineMapper('user')

store.find('user', 1).catch(function (err) {
  console.log(err)
})
github js-data / js-data-http / build_examples / webpack / app.js View on Github external
var JSData = require('js-data')
// normally this would be "var HttpAdapter = require('js-data-http')"
var HttpAdapter = require('../../')

document.getElementById('main').innerHTML = HttpAdapter.version.full

var adapter = new HttpAdapter()
var store = new JSData.DataStore()
store.registerAdapter('http', adapter, { default: true })
store.defineMapper('user')

store.find('user', 1).catch(function (err) {
  console.log(err)
})
github NullVoxPopuli / tanqueReact / frontend / js / data / store.js View on Github external
import { DataStore } from 'js-data';
import { HttpAdapter } from 'js-data-http';

const store = new DataStore();

store.registerAdapter('http', new HttpAdapter(), { default: true });

import User from './models/user';
import Chat from './models/chat-room';
import Message from './models/message';

store.defineMapper('user', User);
store.defineMapper('chatRoom', Chat);
store.defineMapper('message', Message);

// There MUST be an 'all-chat'
store.add('chatRoom', {
  id: 'all-chat',
});
github js-data / js-data-examples / client / react / src / store.js View on Github external
import * as relations from '../../../_shared/relations'

const convertToDate = function (record) {
  if (typeof record.created_at === 'string') {
    record.created_at = new Date(record.created_at)
  }
  if (typeof record.updated_at === 'string') {
    record.updated_at = new Date(record.updated_at)
  }
}

export const adapter = new HttpAdapter({
  // Our API sits behind the /api path
  basePath: '/api'
})
export const store = new DataStore({
  mapperDefaults: {
    // Override the original to make sure the date properties are actually Date
    // objects
    createRecord (props, opts) {
      const result = this.constructor.prototype.createRecord.call(this, props, opts)
      if (Array.isArray(result)) {
        result.forEach(convertToDate)
      } else if (this.is(result)) {
        convertToDate(result)
      }
      return result
    }
  }
})

store.registerAdapter('http', adapter, { default: true })
github cassioscabral / rateissuesfront / src / helpers / store.js View on Github external
// Use DataStore instead of Container in the browser
import {DataStore} from 'js-data'
import adapter, {dataSource} from './adapter'

// Create a store to hold your Mappers
const store = new DataStore()

store.registerAdapter(dataSource, adapter, {default: true})

const category = store.defineMapper('category',{
  relations: {
    hasMany: {
      project: {
        foreignKeys: 'categoryIds',
        localField: 'projects'
      }
    }
  }
})
const tech = store.defineMapper('tech')
const project = store.defineMapper('project',{
  relations: {