How to use the @aurelia/kernel.Metadata.getOwn function in @aurelia/kernel

To help you get started, we’ve selected a few @aurelia/kernel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aurelia / aurelia / packages / runtime / dist / esnext / rendering-engine.js View on Github external
definition = partialDefinition;
        }
        else if (Metadata.hasOwn(CustomElement.name, partialDefinition)) {
            definition = Metadata.getOwn(CustomElement.name, partialDefinition);
        }
        else {
            definition = CustomElementDefinition.create(partialDefinition);
            // Make sure the full definition can be retrieved both from the partialDefinition as well as its dynamically created class
            Metadata.define(CustomElement.name, definition, partialDefinition);
            Metadata.define(CustomElement.name, definition, definition.Type);
        }
        if (parentContext == void 0) {
            parentContext = this.container;
        }
        const factorykey = CustomElement.keyFrom(`${parentContext.path}:factory`);
        let factory = Metadata.getOwn(factorykey, definition);
        if (factory === void 0) {
            const template = this.templateFromSource(dom, definition, parentContext, void 0);
            factory = new ViewFactory(definition.name, template, this.lifecycle);
            factory.setCacheSize(definition.cache, true);
            if (definition.injectable === null) {
                // Never cache view factories for an injectable since we always need a new render context per instance
                Metadata.define(factorykey, factory, definition);
            }
        }
        return factory;
    }
    templateFromSource(dom, definition, parentContext, componentType, componentInstance) {
github aurelia / aurelia / packages / jit / src / resource-model.ts View on Github external
if (resolver === void 0) {
        return null;
      }
    }

    if (resolver === null) {
      return null;
    }

    if (typeof resolver.getFactory === 'function') {
      const factory = resolver.getFactory(this.container);
      if (factory === null || factory === void 0) {
        return null;
      }

      const definition = Metadata.getOwn(kind.name, factory.Type);
      if (definition === void 0) {
        // TODO: we may want to log a warning here, or even throw. This would happen if a dependency is registered with a resource-like key
        // but does not actually have a definition associated via the type's metadata. That *should* generally not happen.
        return null;
      }

      return definition;
    }

    return null;
  }
github aurelia / aurelia / packages / __tests__ / 1-kernel / metadata.spec.ts View on Github external
it('returns undefined when metadata exists on the prototype and with key', function () {
      const prototype = {};
      const obj = Object.create(prototype);
      Metadata.define('key', 'value', prototype, 'name');

      const actual = Metadata.getOwn('key', obj, 'name');

      assert.strictEqual(actual, void 0);
    });
  });
github aurelia / aurelia / packages / router / dist / esnext / router.js View on Github external
CustomElementFor(node) {
        let cur = node;
        while (cur !== null) {
            const nodeResourceName = cur.nodeName.toLowerCase();
            const controller = Metadata.getOwn(`${CustomElement.name}:${nodeResourceName}`, cur)
                || Metadata.getOwn(CustomElement.name, cur);
            if (controller !== void 0) {
                return controller;
            }
            cur = DOM.getEffectiveParentNode(cur);
        }
        return (void 0);
    }
}
github aurelia / aurelia / packages / runtime / dist / esnext / resources / custom-attribute.js View on Github external
getAnnotation(Type, prop) {
        return Metadata.getOwn(Protocol.annotation.keyFor(prop), Type);
    },
};
github aurelia / aurelia / packages / runtime / dist / esnext / templating / bindable.js View on Github external
getAll(Type) {
        const propStart = Bindable.name.length + 1;
        const defs = [];
        const prototypeChain = getPrototypeChain(Type);
        let iProto = prototypeChain.length;
        let iDefs = 0;
        let keys;
        let keysLen;
        let Class;
        while (--iProto >= 0) {
            Class = prototypeChain[iProto];
            keys = Protocol.annotation.getKeys(Class).filter(isBindableAnnotation);
            keysLen = keys.length;
            for (let i = 0; i < keysLen; ++i) {
                defs[iDefs++] = Metadata.getOwn(Bindable.name, Class, keys[i].slice(propStart));
            }
        }
        return defs;
    },
};
github aurelia / aurelia / packages / runtime / dist / esnext / rendering-engine.js View on Github external
templateFromSourceCore(dom, definition, parentContext, componentType, componentInstance) {
        const renderContext = new RenderContext(dom, parentContext, definition.dependencies, componentType, componentInstance);
        if (definition.template != void 0 && definition.needsCompile) {
            const compiledDefinitionKey = CustomElement.keyFrom(`${parentContext.path}:compiled-definition`);
            let compiledDefinition = Metadata.getOwn(compiledDefinitionKey, definition);
            if (compiledDefinition === void 0) {
                compiledDefinition = this.compiler.compile(dom, definition, renderContext.createRuntimeCompilationResources(), ViewCompileFlags.surrogate);
                Metadata.define(compiledDefinitionKey, compiledDefinition, definition);
            }
            return this.templateFactory.create(renderContext, compiledDefinition);
        }
        return this.templateFactory.create(renderContext, definition);
    }
};
github aurelia / aurelia / packages / router / dist / esnext / router.js View on Github external
CustomElementFor(node) {
        let cur = node;
        while (cur !== null) {
            const nodeResourceName = cur.nodeName.toLowerCase();
            const controller = Metadata.getOwn(`${CustomElement.name}:${nodeResourceName}`, cur)
                || Metadata.getOwn(CustomElement.name, cur);
            if (controller !== void 0) {
                return controller;
            }
            cur = DOM.getEffectiveParentNode(cur);
        }
        return (void 0);
    }
}
github aurelia / aurelia / packages / runtime / dist / esnext / definitions.js View on Github external
return function (target) {
        const key = Protocol.annotation.keyFor('aliases');
        const existing = Metadata.getOwn(key, target);
        if (existing === void 0) {
            Metadata.define(key, aliases, target);
        }
        else {
            existing.push(...aliases);
        }
    };
}