new ResourcePhantomIdFactoryService()
Factory service to generate new resource phantom id generators.
- Source:
- See:
Example
// ResourcePhantomIdFactory that creates negative IDs as phantom IDs (NOTE: this is already a build-in
// phantom ID factory, so you do not have to implement this - @see ResourcePhantomIdNegativeInt)
inject(function (ResourceFactoryService, ResourcePhantomIdFactoryService) {
var
lastPkValue = 0,
generator = ResourcePhantomIdFactoryService.createPhantomIdFactory({
generate: function () {
return --lastPkValue;
},
is: function (pkValue) {
return pkValue < 0;
}
}),
service = ResourceFactoryService('TestResourceService', 'http://test/:pk/', {
phantomIdGenerator: generator
}),
phantomInstance1 = service.new(),
phantomInstance2 = service.new();
expect(phantomInstance1.$isPhantom()).toBe(true);
expect(phantomInstance2.$isPhantom()).toBe(true);
// Change IDs to non-negative numbers
phantomInstance1.pk = 1;
phantomInstance2.pk = 2;
expect(phantomInstance1.$isPhantom()).toBe(false);
expect(phantomInstance2.$isPhantom()).toBe(false);
});
Methods
(static) createPhantomIdFactory(config) → {ResourcePhantomIdFactory}
Creates a new phantom id generator with the given configuration.
Parameters:
Name | Type | Description |
---|---|---|
config |
Object | Configuration object for new phantom ID factory |
Returns:
New phantom ID factory instance