Global

Members

ResourcePhantomIdNegativeInt

Resource phantom id generator that generates negative integer IDs

Source:
Example
// Using `ResourcePhantomIdNegativeInt`
inject(function (ResourceFactoryService, ResourcePhantomIdNegativeInt) {
    var
        service = ResourceFactoryService('TestResourceService', 'http://test/:pk/', {
            phantomIdGenerator: ResourcePhantomIdNegativeInt
        }),
        phantomInstance1 = service.new(),
        phantomInstance2 = service.new();

    // Test if IDs are negative
    expect(phantomInstance1.pk).toBe(-1);
    expect(phantomInstance2.pk).toBe(-2);

    // Test if instances are marked as phantom
    expect(phantomInstance1.$isPhantom()).toBe(true);
    expect(phantomInstance2.$isPhantom()).toBe(true);

    // Change IDs
    phantomInstance1.pk = 1;
    phantomInstance2.pk = 2;

    // Test if instances are marked as concrete for positive IDs
    expect(phantomInstance1.$isPhantom()).toBe(false);
    expect(phantomInstance2.$isPhantom()).toBe(false);
});

ResourcePhantomIdUuid4

Resource phantom id generator that generates UUID4 IDs

Source:
Example
// Using `ResourcePhantomIdUuid4`
inject(function (ResourceFactoryService, ResourcePhantomIdUuid4) {
    var
        service = ResourceFactoryService('TestResourceService', 'http://test/:pk/', {
            phantomIdGenerator: ResourcePhantomIdUuid4
        }),
        phantomInstance1 = service.new(),
        phantomInstance2 = service.new();

    // Test if IDs are valid UUID4s
    expect(phantomInstance1.pk).toMatch(/[\d\w]{8}-[\d\w]{4}-[\d\w]{4}-[\d\w]{4}-[\d\w]{12}/i);
    expect(phantomInstance2.pk).toMatch(/[\d\w]{8}-[\d\w]{4}-[\d\w]{4}-[\d\w]{4}-[\d\w]{12}/i);

    // Test if instances are marked as phantom as long as UUID4s match one of the generated
    expect(phantomInstance1.$isPhantom()).toBe(true);
    expect(phantomInstance2.$isPhantom()).toBe(true);

    // Change IDs
    phantomInstance1.pk = '00000000-0000-0000-0000-000000000000';
    phantomInstance2.pk = '11111111-1111-1111-1111-111111111111';

    // Test if instances are marked as concrete for not generated UUID4s
    expect(phantomInstance1.$isPhantom()).toBe(false);
    expect(phantomInstance2.$isPhantom()).toBe(false);
});

Type Definitions

HttpCacheInstance

A $http compatible cache instance

Type:
  • Object
Source:

ResourceCacheServiceMeta

Object holding resource cache meta information.

Type:
  • Object
Source:

ResourceInstance

A resource instance created via an instance of ResourceFactoryService.

Type:
  • Object | Array.<Object>
Source: