Rename function generation methods of HalLink

pull/4594/head
Alex Dik 8 years ago
parent c3b36862d8
commit 4cece53227
  1. 12
      frontend/app/components/api/api-v3/hal-link/hal-link.service.test.ts
  2. 6
      frontend/app/components/api/api-v3/hal-link/hal-link.service.ts
  3. 4
      frontend/app/components/api/api-v3/hal-resources/hal-resource.service.ts

@ -166,14 +166,14 @@ describe('HalLink service', () => {
});
describe('when using the link function wrapper', () => {
describe('when making the link callable', () => {
var func;
const runChecks = () => {
it('should return a function that fetches the data', () => {
func();
$httpBackend.expectGET('/api/link').respond(200);
$httpBackend.flush()
$httpBackend.flush();
});
it('should pass the params to $fetch', () => {
@ -184,16 +184,16 @@ describe('HalLink service', () => {
});
};
describe('when using $toFunc', () => {
describe('when using the instance method', () => {
beforeEach(() => {
func = link.$toFunc();
func = link.$callable();
});
runChecks();
});
describe('when using the static factory function', () => {
describe('when using the static factory method', () => {
beforeEach(() => {
func = HalLink.asFunc(link);
func = HalLink.callable(link);
link = func.$link;
});
runChecks();

@ -43,8 +43,8 @@ export class HalLink implements HalLinkInterface {
return new HalLink(link.href, link.title, link.method, link.templated);
}
public static asFunc(link) {
return HalLink.fromObject(link).$toFunc();
public static callable(link) {
return HalLink.fromObject(link).$callable();
}
/**
@ -72,7 +72,7 @@ export class HalLink implements HalLinkInterface {
return this.$route[this.method === 'delete' && 'remove' || this.method](...params);
}
public $toFunc() {
public $callable() {
const func:any = (...params) => this.$fetch(...params);
func.$link = this;
func.$route = this.$route;

@ -184,7 +184,7 @@ function initializeResource(halResource:HalResource) {
if (link.href) {
if (link.method !== 'get') {
return HalLink.asFunc(link);
return HalLink.callable(link);
}
return createLinkedResource(linkName, link);
@ -218,7 +218,7 @@ function initializeResource(halResource:HalResource) {
function setupLinks() {
setupProperty('links',
link => Array.isArray(link) ? link.map(HalLink.asFunc) : HalLink.asFunc(link));
link => Array.isArray(link) ? link.map(HalLink.callable) : HalLink.callable(link));
}
function setupEmbedded() {

Loading…
Cancel
Save