1.0.7 • Published 6 years ago

@kingjs/descriptor.named.load v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

@kingjs/descriptor.named.load

For each descriptor, replaces properties containing descriptor names the actual descriptor then maps the descriptor.

Usage

var load = require('@kingjs/descriptor.named.load');
var write = require('@kingjs/descriptor.write');

var globalId = 0;

var descriptors = load.call({ 
  baz: { baseFunc: 'bar' },
  foo: { baseFunc: null },
  bar: { baseFunc: 'foo' },
}, o => {
  var id = globalId++;
  o = write.call(o, 'id', id);
  o = write.call(o, 'func', function() {
    var result = this.id;
    if (this.baseFunc)
      result += ' -> ' + this.baseFunc();
    return result;
  });
  return o;
}, {
  baseFunc: o => o.func
});

{
  foo: descriptors.foo.func(),
  bar: descriptors.bar.func(),
  baz: descriptors.baz.func(),
}

result:

{
  foo: '0',
  bar: '1 -> 0',
  baz: '2 -> 1 -> 0'
}

API

declare function load(
  this: DescriptorNamed,
  callback?: (this, value: Descriptor, name: string) => Descriptor,
  refs?: DescriptorNamed | (this, name: string) => DescriptorNested,
  thisArg?: any
): DescriptorNamed

Interfaces

Parameters

  • this: The named of descriptors with properties to load.
  • callback: Maps a descriptor after all refs have been resolved.
  • refs: Paths to the properties to load.
    • descriptor: Optional selector of a property value in load descriptor.
  • thisArg: Passed as this argument to callback.

Returns

Returns a DescriptorNamed whose members have had their references to other members load.

Remarks

Graph of references must form a poset.

Install

With npm installed, run

$ npm install @kingjs/descriptor.named.load

License

MIT

Analytics