Skip to content

Commit

Permalink
Move Resource setup logic to it's own method
Browse files Browse the repository at this point in the history
That way our constructor may have initial parameters (see resource.test.js) and now we have awesome super.setups! (see fixtures).
  • Loading branch information
lubien committed Jul 27, 2016
1 parent c8ee658 commit 57a0e10
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
11 changes: 10 additions & 1 deletion src/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ import Request from './request';
import {Container} from './';

export default class Resource {
/**
* @param {Object} attributes
*/
constructor(attributes) {
this.setup();

this.set(attributes);
}

/**
* @param {Object} params
*/
constructor({service, name, identifierName, collectionRoot, itemRoot}) {
setup({service, name, identifierName, collectionRoot, itemRoot}) {
this.service = service;
this.name = name;
this.identifierName = identifierName;
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/comment-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {Resource} from '../../src';
import {receiveJson, sendJson} from '../../src/format';

export default class CommentResource extends receiveJson(sendJson(Resource)) {
constructor() {
super({
setup() {
super.setup({
service: 'json-placeholder',
name: 'comments',
identifierName: 'id'
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/post-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {Resource} from '../../src';
import {receiveJson, sendJson} from '../../src/format';

export default class PostResource extends receiveJson(sendJson(Resource)) {
constructor() {
super({
setup() {
super.setup({
service: 'json-placeholder',
name: 'posts',
identifierName: 'id'
Expand Down
3 changes: 1 addition & 2 deletions test/resource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ test('Resource.find()', async t => {
});

test('Resource.save()', async t => {
const post = new PostResource();
post.set({
const post = new PostResource({
userId: 1,
title: 'Foo',
body: 'Lorem ipsum'
Expand Down

0 comments on commit 57a0e10

Please sign in to comment.