Skip to content

Commit 27e1279

Browse files
author
Lee Richmond
committed
Add #isType convenience method
1 parent 09bc98c commit 27e1279

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

dist/jsorm.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jsorm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/model.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ export default class Model {
109109
return this._attributes;
110110
}
111111

112+
isType(jsonapiType : string) {
113+
return this.klass.jsonapiType === jsonapiType;
114+
}
115+
112116
set attributes(attrs : Object) {
113117
for(var key in attrs) {
114118
let attributeName = camelize(key);

test/unit/model-test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ import { Person, Author, Book, Genre, Bio } from '../fixtures';
77
let instance;
88

99
describe('Model', function() {
10+
describe('#isType', function() {
11+
it('checks the jsonapiType of class', function() {
12+
instance = new Author()
13+
expect(instance.isType('authors')).to.eq(true)
14+
expect(instance.isType('people')).to.eq(false)
15+
});
16+
});
17+
1018
describe('#fromJsonapi', function() {
1119
let doc = {
1220
data: {

0 commit comments

Comments
 (0)