How to use piral-base - 10 common examples

To help you get started, we’ve selected a few piral-base 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 smapiot / piral / src / packages / piral-core / src / components / Mediator.tsx View on Github external
React.useEffect(() => {
    const { connect, disconnect } = startLoadingPilets(options);
    const notifier: PiletsLoading = (error, pilets, loaded) => {
      initialize(!loaded, error, pilets);
    };
    connect(notifier);
    return () => disconnect(notifier);
  }, []);
  // tslint:disable-next-line:no-null-keyword
github smapiot / piral / src / packages / piral-core / src / helpers.tsx View on Github external
ws.onmessage = ({ data }) => {
          const meta = JSON.parse(data);
          const getter = getDependencyResolver(globalDependencies, getDependencies);
          const fetcher = (url: string) =>
            fetch(url, {
              method: 'GET',
              cache: 'reload',
            }).then(m => m.text());
          loadPilet(meta, getter, fetcher).then(pilet => {
            try {
              const newApi = createApi(pilet);
              context.injectPilet(pilet);
              pilet.setup(newApi);
            } catch (error) {
              console.error(error);
            }
          });
        };
github smapiot / piral / src / packages / piral-core / src / helpers.tsx View on Github external
ws.onmessage = ({ data }) => {
          const meta = JSON.parse(data);
          const getter = getDependencyResolver(globalDependencies, getDependencies);
          const fetcher = (url: string) =>
            fetch(url, {
              method: 'GET',
              cache: 'reload',
            }).then(m => m.text());
          loadPilet(meta, getter, fetcher).then(pilet => {
            try {
              const newApi = createApi(pilet);
              context.injectPilet(pilet);
              pilet.setup(newApi);
            } catch (error) {
              console.error(error);
            }
          });
        };
github smapiot / piral / src / packages / piral-search / src / create.ts View on Github external
function createSearchRegistration(
  pilet: string,
  search: SearchHandler,
  settings: SearchSettings = {},
): SearchProviderRegistration {
  const { onlyImmediate = false, onCancel = noop, onClear = noop } = settings;
  return {
    pilet,
    onlyImmediate,
    cancel: isfunc(onCancel) ? onCancel : noop,
    clear: isfunc(onClear) ? onClear : noop,
    search,
  };
}
github smapiot / piral / src / packages / piral-core / src / createInstance.tsx View on Github external
} = config;
  const globalState = createGlobalState(state);
  const events = createListener(globalState);
  const context = createActions(globalState, events);
  const createApi = defaultApiCreator(context, Array.isArray(extendApi) ? extendApi : [extendApi]);
  const root = createApi({
    name: 'root',
    version: process.env.BUILD_PCKG_VERSION || '1.0.0',
    hash: '',
  });
  const options = createArbiterOptions({
    context,
    createApi,
    availablePilets,
    getDependencies,
    strategy: isfunc(async) ? async : async ? blazingStrategy : standardStrategy,
    requestPilets,
  });

  if (actions) {
    includeActions(context, actions);
  }

  return {
    ...events,
    createApi,
    context,
    root,
    options,
  };
}
github smapiot / piral / src / packages / piral-feeds / src / utils.ts View on Github external
export function createFeedOptions(
  id: string,
  resolver: FeedResolver | FeedConnectorOptions,
): ConnectorDetails {
  if (isfunc(resolver)) {
    return {
      id,
      connect() {
        return () => {};
      },
      initialize() {
        return resolver();
      },
      update(data) {
        return Promise.resolve(data);
      },
      immediately: false,
    };
  } else {
    return {
      id,
github smapiot / piral / src / packages / piral-forms / src / usePrompt.ts View on Github external
const beforeUnload = (ev: BeforeUnloadEvent) => {
        const msg = isfunc(message) ? message() : message;
        ev.returnValue = msg;
        return msg;
      };
      const unlisten = onTransition && history.listen(onTransition);
github smapiot / piral / src / packages / piral-core / src / components / withApi.tsx View on Github external
componentDidUpdate() {
      const { current, previous } = this;
      const { $component, innerProps } = this.props;
      const { update } = $component;

      if (current !== previous) {
        this.componentWillUnmount();
        this.componentDidMount();
      } else if (isfunc(update)) {
        update(current, innerProps, this.context);
      }
    }
github smapiot / piral / src / packages / piral-search / src / create.ts View on Github external
function createSearchRegistration(
  pilet: string,
  search: SearchHandler,
  settings: SearchSettings = {},
): SearchProviderRegistration {
  const { onlyImmediate = false, onCancel = noop, onClear = noop } = settings;
  return {
    pilet,
    onlyImmediate,
    cancel: isfunc(onCancel) ? onCancel : noop,
    clear: isfunc(onClear) ? onClear : noop,
    search,
  };
}
github smapiot / piral / src / packages / piral-core / src / components / withApi.tsx View on Github external
componentDidMount() {
      const node = this.current;
      const { $component, innerProps } = this.props;
      const { mount } = $component;

      if (node && isfunc(mount)) {
        mount(node, innerProps, this.context);
      }

      this.previous = node;
    }

piral-base

The base library for creating a Piral instance.

MIT
Latest version published 9 days ago

Package Health Score

84 / 100
Full package analysis