Skip to content

Commit

Permalink
[FIX DOCS] Docs updates for Packages to fix missing docs and broken l…
Browse files Browse the repository at this point in the history
…inks (emberjs#6449)

* remove ember-data and DS namespace/module
* eliminate usage of DS.Store in the documentation
* improve Store documentation
* configure Store docs to be the main docs for the @ember-data/store package
* cleanup Model docs
* fix adapter/serializer location and main docs
* cleanup DS. usage in docs
* Fix/ds docs (emberjs#6456)
* [DOCS] Fix some links (emberjs#6507)

Co-Authored-By: Gaurav Munjal <Gaurav0@aol.com>
  • Loading branch information
runspired and Gaurav0 committed Sep 27, 2019
1 parent 189b1ba commit ef226de
Show file tree
Hide file tree
Showing 36 changed files with 350 additions and 326 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,7 @@ post.constructor.typeKey => postSnapshot.typeKey
If you need to access the underlying record of a snapshot you can do so by
accessing `snapshot.record`.

The full API reference of `DS.Snapshot` can be found [here](https://emberjs.com/api/data/classes/DS.Snapshot.html).
The full API reference of `DS.Snapshot` can be found [here](https://api.emberjs.com/ember-data/release/classes/Snapshot).

#### Changes

Expand Down Expand Up @@ -2097,7 +2097,7 @@ to set metadata.

##### `ManyArray`s are no longer `RecordArray`s

[ManyArray](https://emberjs.com/api/data/classes/DS.ManyArray.html),
[ManyArray](https://api.emberjs.com/ember-data/release/classes/ManyArray),
the object Ember Data uses to represent `DS.hasMany` relationships has
been changed so it no longer extends from `RecordArray`. This means if
you were relying on the RecordArray's `content` property to access the
Expand Down
26 changes: 11 additions & 15 deletions packages/-ember-data/addon/-private/core.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
/**
@module @ember-data
@main @ember-data
*/

import Namespace from '@ember/application/namespace';
import Ember from 'ember';
import VERSION from 'ember-data/version';

/**
@module ember-data
*/

/**
All Ember Data classes, methods and functions are defined inside of this namespace.
@class DS
@static
*/
* @property VERSION
* @public
* @static
* @for @ember-data
*/

/**
@property VERSION
@type String
@static
*/
const DS = Namespace.create({
VERSION: VERSION,
name: 'DS',
});

if (Ember.libraries) {
Ember.libraries.registerCoreLibrary('Ember Data', DS.VERSION);
Ember.libraries.registerCoreLibrary('Ember Data', VERSION);
}

export default DS;
75 changes: 71 additions & 4 deletions packages/-ember-data/addon/-private/system/debug/debug-adapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
@module ember-data
@module @ember-data/debug
*/
import { addObserver, removeObserver } from '@ember/object/observers';

Expand All @@ -10,11 +10,12 @@ import { assert } from '@ember/debug';
import { get } from '@ember/object';
import Model from '@ember-data/model';

/*
Extend `Ember.DataAdapter` with ED specific code.
/**
Implements `@ember/debug/data-adapter` with for EmberData
integration with the ember-inspector.
@class DebugAdapter
@extends Ember.DataAdapter
@extends DataAdapter
@private
*/
export default DataAdapter.extend({
Expand All @@ -26,6 +27,13 @@ export default DataAdapter.extend({
];
},

/**
Detect whether a class is a Model
@public
@method detect
@param {Model} typeClass
@return {Boolean} Whether the typeClass is a Model class or not
*/
detect(typeClass) {
return typeClass !== Model && Model.detect(typeClass);
},
Expand All @@ -38,6 +46,15 @@ export default DataAdapter.extend({
);
},

/**
Get the columns for a given model type
@public
@method columnsForType
@param {Model} typeClass
@return {Array} An array of columns of the following format:
name: {String} The name of the column
desc: {String} Humanized description (what would show in a table column name)
*/
columnsForType(typeClass) {
let columns = [
{
Expand All @@ -57,6 +74,16 @@ export default DataAdapter.extend({
return columns;
},

/**
Fetches all loaded records for a given type
@public
@method getRecords
@param {Model} modelClass of the record
@param {String} modelName of the record
@return {Array} An array of Model records
This array will be observed for changes,
so it should update when new records are added/removed
*/
getRecords(modelClass, modelName) {
if (arguments.length < 2) {
// Legacy Ember.js < 1.13 support
Expand All @@ -72,6 +99,14 @@ export default DataAdapter.extend({
return this.get('store').peekAll(modelName);
},

/**
Gets the values for each column
This is the attribute values for a given record
@public
@method getRecordColumnValues
@param {Model} record to get values from
@return {Object} Keys should match column names defined by the model type
*/
getRecordColumnValues(record) {
let count = 0;
let columnValues = { id: get(record, 'id') };
Expand All @@ -85,6 +120,13 @@ export default DataAdapter.extend({
return columnValues;
},

/**
Returns keywords to match when searching records
@public
@method getRecordKeywords
@param {Model} record
@return {Array} Relevant keywords for search based on the record's attribute values
*/
getRecordKeywords(record) {
let keywords = [];
let keys = A(['id']);
Expand All @@ -93,6 +135,14 @@ export default DataAdapter.extend({
return keywords;
},

/**
Returns the values of filters defined by `getFilters`
These reflect the state of the record
@public
@method getRecordFilterValues
@param {Model} record
@return {Object} The record state filter values
*/
getRecordFilterValues(record) {
return {
isNew: record.get('isNew'),
Expand All @@ -101,6 +151,14 @@ export default DataAdapter.extend({
};
},

/**
Returns a color that represents the record's state
@public
@method getRecordColor
@param {Model} record
@return {String} The record color
Possible options: black, blue, green
*/
getRecordColor(record) {
let color = 'black';
if (record.get('isNew')) {
Expand All @@ -111,6 +169,15 @@ export default DataAdapter.extend({
return color;
},

/**
Observes all relevant properties and re-sends the wrapped record
when a change occurs
@public
@method observerRecord
@param {Model} record
@param {Function} recordUpdated Callback used to notify changes
@return {Function} The function to call to remove all observers
*/
observeRecord(record, recordUpdated) {
let releaseMethods = A();
let keysToObserve = A(['id', 'isNew', 'hasDirtyAttributes']);
Expand Down
6 changes: 0 additions & 6 deletions packages/-ember-data/addon/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { VERSION } from '@ember/version';
import EmberError from '@ember/error';

/**
Ember Data
@module ember-data
@main ember-data
*/

if (VERSION.match(/^1\.([0-9]|1[0-2])\./)) {
throw new EmberError(
'Ember Data requires at least Ember 1.13.0, but you have ' +
Expand Down
3 changes: 0 additions & 3 deletions packages/-ember-data/addon/relationships.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
/**
@module ember-data
*/
export { belongsTo, hasMany } from '@ember-data/model';
39 changes: 3 additions & 36 deletions packages/-ember-data/app/initializers/ember-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,11 @@ import setupContainer from 'ember-data/setup-container';
import 'ember-data';

/*
This code initializes EmberData in an Ember application.
This code initializes Ember-Data onto an Ember application.
If an Ember.js developer defines a subclass of DS.Store on their application,
as `App.StoreService` (or via a module system that resolves to `service:store`)
this code will automatically instantiate it and make it available on the
router.
Additionally, after an application's controllers have been injected, they will
each have the store made available to them.
For example, imagine an Ember.js application with the following classes:
```app/services/store.js
import DS from 'ember-data';
export default DS.Store.extend({
adapter: 'custom'
});
```
```app/controllers/posts.js
import { Controller } from '@ember/controller';
export default Controller.extend({
// ...
});
When the application is initialized, `ApplicationStore` will automatically be
instantiated, and the instance of `PostsController` will have its `store`
property set to that instance.
Note that this code will only be run if the `ember-application` package is
loaded. If Ember Data is being used in an environment other than a
typical application (e.g., node.js where only `ember-runtime` is available),
this code will be ignored.
It ensures that the `store` service is automatically injected
as the `store` property on all routes and controllers.
*/

export default {
name: 'ember-data',
initialize: setupContainer,
Expand Down
12 changes: 0 additions & 12 deletions packages/-ember-data/tests/helpers/custom-adapter.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function(

assert.expectAssertion(() => {
message.get('user');
}, /You looked up the 'user' relationship on a 'message' with id 1 but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async \(`DS.belongsTo\({ async: true }\)`\)/);
}, /You looked up the 'user' relationship on a 'message' with id 1 but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async \(`belongsTo\({ async: true }\)`\)/);
});

test('Rollbacking attributes for a deleted record restores implicit relationship - async', function(assert) {
Expand Down
21 changes: 9 additions & 12 deletions packages/adapter/addon/-private/build-url-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import { pluralize } from 'ember-inflector';
*/

/**
WARNING: This interface is likely to change in order to accommodate [RFC: Ember Data url templates](https://github.com/emberjs/rfcs/pull/4)
## Using BuildURLMixin
To use URL building, include the mixin when extending an adapter, and call `buildURL` where needed.
Expand Down Expand Up @@ -41,7 +38,7 @@ export default Mixin.create({
By default, it pluralizes the type's name (for example, 'post'
becomes 'posts' and 'person' becomes 'people'). To override the
pluralization see [pathForType](#method_pathForType).
pluralization see [pathForType](BuildUrlMixin/methods/pathForType?anchor=pathForType).
If an ID is specified, it adds the ID to the path generated
for the type, separated by a `/`.
Expand All @@ -52,7 +49,7 @@ export default Mixin.create({
@method buildURL
@param {String} modelName
@param {(String|Array|Object)} id single id or array of ids or query
@param {(DS.Snapshot|Array)} snapshot single snapshot or array of snapshots
@param {(Snapshot|SnapshotRecordArray)} snapshot single snapshot or array of snapshots
@param {String} requestType
@param {Object} query object of query parameters to send for query requests.
@return {String} url
Expand Down Expand Up @@ -138,7 +135,7 @@ export default Mixin.create({
@method urlForFindRecord
@param {String} id
@param {String} modelName
@param {DS.Snapshot} snapshot
@param {Snapshot} snapshot
@return {String} url
*/
Expand All @@ -163,7 +160,7 @@ export default Mixin.create({
@method urlForFindAll
@param {String} modelName
@param {DS.SnapshotRecordArray} snapshot
@param {SnapshotRecordArray} snapshot
@return {String} url
*/
urlForFindAll(modelName, snapshot) {
Expand Down Expand Up @@ -273,7 +270,7 @@ export default Mixin.create({
@method urlForFindHasMany
@param {String} id
@param {String} modelName
@param {DS.Snapshot} snapshot
@param {Snapshot} snapshot
@return {String} url
*/
urlForFindHasMany(id, modelName, snapshot) {
Expand All @@ -300,7 +297,7 @@ export default Mixin.create({
@method urlForFindBelongsTo
@param {String} id
@param {String} modelName
@param {DS.Snapshot} snapshot
@param {Snapshot} snapshot
@return {String} url
*/
urlForFindBelongsTo(id, modelName, snapshot) {
Expand All @@ -325,7 +322,7 @@ export default Mixin.create({
@method urlForCreateRecord
@param {String} modelName
@param {DS.Snapshot} snapshot
@param {Snapshot} snapshot
@return {String} url
*/
urlForCreateRecord(modelName, snapshot) {
Expand All @@ -350,7 +347,7 @@ export default Mixin.create({
@method urlForUpdateRecord
@param {String} id
@param {String} modelName
@param {DS.Snapshot} snapshot
@param {Snapshot} snapshot
@return {String} url
*/
urlForUpdateRecord(id, modelName, snapshot) {
Expand All @@ -375,7 +372,7 @@ export default Mixin.create({
@method urlForDeleteRecord
@param {String} id
@param {String} modelName
@param {DS.Snapshot} snapshot
@param {Snapshot} snapshot
@return {String} url
*/
urlForDeleteRecord(id, modelName, snapshot) {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter/addon/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { assert } from '@ember/debug';
- `ServerError`
To create a custom error to signal a specific error state in communicating
with an external API, extend the `DS.AdapterError`. For example, if the
with an external API, extend the `AdapterError`. For example, if the
external API exclusively used HTTP `503 Service Unavailable` to indicate
it was closed for maintenance:
Expand Down
Loading

0 comments on commit ef226de

Please sign in to comment.