public open(modalInstance: SkyModalInstance, component: any, providers?: any[]) {
    let factory = this.resolver.resolveComponentFactory(component);
    let hostService = new SkyModalHostService();

    providers = providers || [];

    providers.push({
      provide: SkyModalHostService,
      useValue: hostService
    });

    let resolvedProviders = ReflectiveInjector.resolve(providers);

    let injector = ReflectiveInjector.fromResolvedProviders(resolvedProviders, this.injector);

    let modalComponentRef = this.target.createComponent(factory, undefined, injector);

    modalInstance.componentInstance = modalComponentRef.instance;

    function closeModal() {
      hostService.destroy();
      modalComponentRef.destroy();
    }

    hostService.close.subscribe((modalComponent: SkyModalComponent) => {
      closeModal();
    });

    modalInstance.setCloseCallback(() => {
      closeModal();
    });
  }
Example #2
0
  return async(): Promise<BootstrapResponse> => {

    try {
      deferredLog('info', 'Bootstrapping server');
      const resolvedProviders: ProviderType[] = await Promise.all(CORE_PROVIDERS.concat(providers));

      //initialize all bootstrappers (in order they need to be created)
      const resolvedBootstrappers: EntityBootstrapper[] = [
        new ModelBootstrapper,
        new ServiceBootstrapper,
        new MigrationBootstrapper,
        new SeederBootstrapper,
        new ControllerBootstrapper,
      ];

      const bootrapperProviders: any[] = resolvedBootstrappers.reduce((result: any[], bootstrapper: EntityBootstrapper) => {
        return result.concat(bootstrapper.getInjectableEntities());
      }, []);

      const mergedProviders = ReflectiveInjector.resolve(bootrapperProviders.concat(resolvedProviders));

      const injector = ReflectiveInjector.fromResolvedProviders(mergedProviders);

      logger = injector.get(Logger)
        .source('bootstrap');

      // iterate over any logs that have been deferred
      deferredLogs.forEach((log: DeferredLog) => {
        logger[log.level](...log.messages);
      });
      deferredLogs = []; //clear buffer

      // iterate over all of the resolved bootstrappers, invoking the bootstrap to initialize the
      // entities. iteration is completed in serial so that bootstrappers that depend on other
      // entities won't invoke until those other entities are finished intializing
      await resolvedBootstrappers.reduce(async(current: Promise<void>, next: EntityBootstrapper): Promise<void> => {

        await current;

        return Promise.resolve(next.setInjector(injector).invokeBootstrap());

      }, Promise.resolve()); //initial value
      // get vars for the bootstrapper
      const server: Server = injector.get(Server);

      let response = {injector, server, logger};

      if (afterBootstrap) {
        await afterBootstrap(response);
        // await Promise.resolve(afterBootstrap(response));
        return response;
      }

      return response;
    } catch (e) {
      handleBootstrapError(e, logger);
    }

  }
 /**
  * Helper methods to add ComponentClass(like modal backdrop) with options
  * of type ComponentOptionsClass to element next to application root
  * or next to provided instance of view container
  * @param ComponentClass - @Component class
  * @param ComponentOptionsClass - options class
  * @param options - instance of options
  * @returns {ComponentRef<T>} - returns ComponentRef<T>
  */
 public appendNextToRoot<T>(ComponentClass:Type<T>,
                            ComponentOptionsClass:any,
                            options:any):ComponentRef<T> {
   let location = this.getRootViewContainerRef();
   let providers = ReflectiveInjector.resolve([
     {provide: ComponentOptionsClass, useValue: options}
   ]);
   return this.appendNextToLocation(ComponentClass, location, providers);
 }
Example #4
0
  /**
   * A helper function for derived classes to create backdrop & container
   * @param dialogRef
   * @param backdrop
   * @param container
   * @returns { backdropRef: ComponentRef<B>, containerRef: ComponentRef<C> }
   *
   * @deprecated use createBackdrop and createContainer instead
   */
  protected createModal<B, C>(dialogRef: DialogRef<any>, backdrop: Class<B>, container: Class<C>)
                                : { backdropRef: ComponentRef<B>, containerRef: ComponentRef<C> } {
    const b = ReflectiveInjector.resolve([{provide: DialogRef, useValue: dialogRef}]);

    return {
      backdropRef: dialogRef.overlayRef.instance.addComponent<B>(backdrop, b),
      containerRef: dialogRef.overlayRef.instance.addComponent<C>(container, b)
    };
  }
Example #5
0
			this._cr.resolveComponent(TooltipComponent).then((cmpFactory: ComponentFactory<TooltipComponent>) => {
				// Create reflective injector to provide an instance of TooltipData 
				let providers = ReflectiveInjector.resolve([
					{ provide: TooltipData, useValue: new TooltipData(el, text, align) },
				]);
				let injector = ReflectiveInjector.fromResolvedProviders(providers, this.viewContainer.parentInjector);

				// Create the component, outputs a promise...
				return this.viewContainer.createComponent(cmpFactory, this.viewContainer.length, injector);
			}).then((cmpRef: ComponentRef<TooltipComponent>) => {
      .then((componentFactory:ComponentFactory<T>) => {
        const viewContainerRef = _viewContainerRef || this.getRootViewContainerRef();
        let bindings = ReflectiveInjector.resolve([
          new Provider(ComponentOptionsClass, {useValue: options})
        ]);
        const ctxInjector = viewContainerRef.parentInjector;

        const childInjector = Array.isArray(bindings) && bindings.length > 0 ?
          ReflectiveInjector.fromResolvedProviders(bindings, ctxInjector) : ctxInjector;
        return viewContainerRef.createComponent(componentFactory, viewContainerRef.length, childInjector);
      });
Example #7
0
  protected createContainer<T>(
    dialogRef: DialogRef<any>,
    ContainerComponent: Class<T>,
    content: string | TemplateRef<any> | Type<any>,
    bindings?: ResolvedReflectiveProvider[]): ComponentRef<T> {

    const b = ReflectiveInjector.resolve([{provide: DialogRef, useValue: dialogRef}])
      .concat(bindings || []);

    let nodes: any[] = dialogRef.overlayRef.instance.getProjectables(content, b);
    return dialogRef.overlayRef.instance.addComponent<T>(ContainerComponent, b, nodes);
  }
function createBindings(config: OneButtonPresetData): ResolvedReflectiveBinding[] {
    config.buttons = [
        {
            cssClass: config.okBtnClass,
            caption: config.okBtn,
            onClick: (modalComponent: MessageModal, $event?: MouseEvent) =>
                modalComponent.dialog.close(true)
        }
    ];

    return ReflectiveInjector.resolve([
        provide(MessageModalContext, {useValue: config})
    ]);
}
  render(dialog: DialogRef<any>, vcRef: ViewContainerRef): ComponentRef<ModalOverlay> {
    const b = ReflectiveInjector.resolve([
      { provide: DialogRef, useValue: dialog }
    ]);

    const cmpRef = createComponent(this._cr, ModalOverlay, vcRef, b);

    if (dialog.inElement) {
      vcRef.element.nativeElement.appendChild(cmpRef.location.nativeElement);
    } else {
      document.body.appendChild(cmpRef.location.nativeElement);
    }

    return cmpRef;
  }
  public open(modalInstance: SkyModalInstance, component: any, config?: IConfig) {
    let params: IConfig = Object.assign({}, config);
    let factory = this.resolver.resolveComponentFactory(component);
    let hostService = new SkyModalHostService();
    let adapter = this.adapter;

    params.providers.push({
      provide: SkyModalHostService,
      useValue: hostService
    });
    params.providers.push({
      provide: SkyModalConfiguation,
      useValue: params
    });

    adapter.setPageScroll(SkyModalHostService.openModalCount > 0);

    let providers = params.providers /* istanbul ignore next */ || [];
    let resolvedProviders = ReflectiveInjector.resolve(providers);
    let injector = ReflectiveInjector.fromResolvedProviders(resolvedProviders, this.injector);
    let modalComponentRef = this.target.createComponent(factory, undefined, injector);

    modalInstance.componentInstance = modalComponentRef.instance;

    function closeModal() {
      hostService.destroy();
      adapter.setPageScroll(SkyModalHostService.openModalCount > 0);
      modalComponentRef.destroy();
    }

    hostService.close.subscribe((modalComponent: SkyModalComponent) => {
      closeModal();
    });

    modalInstance.setCloseCallback(() => {
      closeModal();
    });
  }
Example #11
0
export function main() {
  BrowserDomAdapter.makeCurrent();
  var iterations = getIntParameter('iterations');

  // This benchmark does not use bootstrap and needs to create a reflector
  setupReflector();
  var bindings = [A, B, C, D, E];
  var injector = ReflectiveInjector.resolveAndCreate(bindings);

  var D_KEY = ReflectiveKey.get(D);
  var E_KEY = ReflectiveKey.get(E);
  var childInjector = injector.resolveAndCreateChild([])
                          .resolveAndCreateChild([])
                          .resolveAndCreateChild([])
                          .resolveAndCreateChild([])
                          .resolveAndCreateChild([]);

  var variousProviders = [A, {provide: B, useClass: C}, [D, [E]], {provide: F, useValue: 6}];

  var variousProvidersResolved = ReflectiveInjector.resolve(variousProviders);

  function getByToken() {
    for (var i = 0; i < iterations; ++i) {
      injector.get(D);
      injector.get(E);
    }
  }
  function getByKey() {
    for (var i = 0; i < iterations; ++i) {
      injector.get(D_KEY);
      injector.get(E_KEY);
    }
  }

  function getChild() {
    for (var i = 0; i < iterations; ++i) {
      childInjector.get(D);
      childInjector.get(E);
    }
  }

  function instantiate() {
    for (var i = 0; i < iterations; ++i) {
      var child = injector.resolveAndCreateChild([E]);
      child.get(E);
    }
  }

  /**
   * Creates an injector with a variety of provider types.
   */
  function createVariety() {
    for (var i = 0; i < iterations; ++i) {
      ReflectiveInjector.resolveAndCreate(variousProviders);
    }
  }

  /**
   * Same as [createVariety] but resolves providers ahead of time.
   */
  function createVarietyResolved() {
    for (var i = 0; i < iterations; ++i) {
      ReflectiveInjector.fromResolvedProviders(variousProvidersResolved);
    }
  }

  bindAction('#getByToken', () => microBenchmark('injectAvg', iterations, getByToken));
  bindAction('#getByKey', () => microBenchmark('injectAvg', iterations, getByKey));
  bindAction('#getChild', () => microBenchmark('injectAvg', iterations, getChild));
  bindAction('#instantiate', () => microBenchmark('injectAvg', iterations, instantiate));
  bindAction('#createVariety', () => microBenchmark('injectAvg', iterations, createVariety));
  bindAction(
      '#createVarietyResolved',
      () => microBenchmark('injectAvg', iterations, createVarietyResolved));
}
Example #12
0
 protected createBackdrop<T>(dialogRef: DialogRef<any>, BackdropComponent: Class<T>): ComponentRef<T> {
   const b = ReflectiveInjector.resolve([{provide: DialogRef, useValue: dialogRef}]);
   return dialogRef.overlayRef.instance.addComponent<T>(BackdropComponent, b);
 }