How to use the preact.options function in preact

To help you get started, we’ve selected a few preact 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 aduth / dones / mocha.config.js View on Github external
// Fake DOM
require( 'browser-env' )();

// Chai plugins
require( 'chai' )
	.use( require( 'sinon-chai' ) );

// Force synchronous Preact rerenders during test, allowing assertions to be
// made immediately following a rerender.
require( 'preact' ).options.debounceRendering = ( render ) => render();

// Constant initialization
global.dones = {
	siteUrl: 'http://example.com',
	userId: 1,
	i18n: {},
};
github bruderstein / unexpected-preact / src / unexpected-preact.js View on Github external
import types from './types/types';
import * as deepAssertions from './assertions/deepAssertions';


const Preact = require('preact');
Preact.options.debounceRendering = function (fn) { return fn(); };



module.exports = {
  name: 'unexpected-preact',

  installInto(expect) {

    expect.installPlugin(require('magicpen-prism'));

    types.installInto(expect);
    deepAssertions.installInto(expect);


    expect.addAssertion([
      ' to match snapshot',
github inkandswitch / capstone / src / modules / preact-render-error / index.ts View on Github external
export default function installRenderErrorHandler() {
  const originalVnode = Preact.options.vnode
  Preact.options.vnode = vnode => {
    if (typeof vnode.nodeName === "function") {
      if (isFunctionalComponent(vnode.nodeName)) {
        vnode.nodeName = wrapFunctionalComponent(vnode.nodeName)
      } else {
        wrapComponent(vnode.nodeName)
      }
    }
    if (originalVnode) {
      originalVnode(vnode)
    }
  }

  function wrapComponent(Component: any) {
    if (
      Component.prototype &&
      Component.prototype.render &&
github louismerlin / repfl / src.e31bb0bc.js View on Github external
exports.useReducer = a;
exports.useEffect = v;
exports.useLayoutEffect = l;
exports.useRef = p;
exports.useImperativeHandle = d;
exports.useMemo = m;
exports.useCallback = s;
exports.useContext = y;
exports.useDebugValue = _;

var _preact = require("preact");

var t,
    u,
    r = [],
    f = _preact.options.render;

_preact.options.render = function (n) {
  f && f(n), t = 0, (u = n.__c).__H && (u.__H.t = q(u.__H.t));
};

var i = _preact.options.diffed;

_preact.options.diffed = function (n) {
  i && i(n);
  var t = n.__c;

  if (t) {
    var u = t.__H;
    u && (u.u = q(u.u));
  }
};
github louismerlin / repfl / src.e31bb0bc.js View on Github external
return n;
  }, t);
}

function y(n) {
  var r = u.context[n.__c];
  if (null == r) return n.__p;
  var f = c(t++);
  return null == f.o && (f.o = !0, r.sub(u)), r.props.value;
}

function _(t, u) {
  _preact.options.useDebugValue && _preact.options.useDebugValue(u ? u(t) : t);
}

_preact.options.unmount = function (n) {
  o && o(n);
  var t = n.__c;

  if (t) {
    var u = t.__H;
    u && u.i.forEach(function (n) {
      return n.p && n.p();
    });
  }
};

var g = function () {};

function w() {
  r.forEach(function (n) {
    n.m = !1, n.__P && (n.__H.t = q(n.__H.t));
github inkandswitch / capstone / src / modules / preact-render-error / index.ts View on Github external
export default function installRenderErrorHandler() {
  const originalVnode = Preact.options.vnode
  Preact.options.vnode = vnode => {
    if (typeof vnode.nodeName === "function") {
      if (isFunctionalComponent(vnode.nodeName)) {
        vnode.nodeName = wrapFunctionalComponent(vnode.nodeName)
      } else {
        wrapComponent(vnode.nodeName)
      }
    }
    if (originalVnode) {
      originalVnode(vnode)
    }
  }

  function wrapComponent(Component: any) {
    if (
      Component.prototype &&
github preactjs / preact / debug.js View on Github external
(function () {
		var _require = require('preact');

		var options = _require.options;

		var oldVnodeOption = options.vnode;

		options.vnode = function (vnode) {
			var nodeName = vnode.nodeName;
			var attributes = vnode.attributes;
			var children = vnode.children;

			if (nodeName === void 0) {
				throw new Error('Undefined component passed to preact.h()');
			}

			if (attributes && attributes.ref !== void 0 && typeof attributes.ref !== 'function') {
				throw new Error('Component\'s "ref" property should be a function,' + (' but [' + typeof attributes.ref + '] passed'));
			}
github theKashey / react-remock / src / patch / preact.ts View on Github external
import {resolver} from '../resolver';

const preact = require('preact');
const oldHandler = preact.options.vnode;

function patchReact(preact: any) {
  preact.options.vnode = (vnode: any) => {
    const {nodeName: type, attributes: props, children: args} = vnode;

    const {type: newType = type, props: newProps = props, children = args} = resolver(type as any, props, args) as any;
    const node = {
      nodeName: newType,
      arguments: newProps,
      children: newProps && newProps.children || children,
    };

    return oldHandler
      ? oldHandler(node)
      : node;
  }
github theKashey / react-remock / src / patch / preact.ts View on Github external
export const disable = () => preact.options.vnode = oldHandler;