Skip to content

Commit

Permalink
Bumps version to v4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelbr committed Nov 11, 2015
1 parent 7cc1e9e commit 4fefa98
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 87 deletions.
262 changes: 178 additions & 84 deletions dist/omniscient.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Omniscient.js v4.0.0
* Omniscient.js v4.1.0
* Authors: @torgeir,@mikaelbr
***************************************/
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.omniscient = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
Expand Down Expand Up @@ -119,12 +119,13 @@ module.exports = factory();
* classDecorator: function(Component), // Allows for decorating created class
*
* // Passed on to `shouldComponentUpdate`
* isCursor: function(cursor), // check if prop is cursor
* unCursor: function (cursor), // convert cursor to object
* isEqualCursor: function (oneCursor, otherCursor), // compares cursor
* isEqualState: function (currentState, nextState), // compares state
* isEqualProps: function (currentProps, nextProps), // compares props
* isImmutable: function (maybeImmutable) // check if object is immutable
* isCursor: function (cursor), // check if is props
* isEqualCursor: function (oneCursor, otherCursor), // check cursor
* isEqualState: function (currentState, nextState), // check state
* isImmutable: function (currentState, nextState), // check if object is immutable
* isEqualProps: function (currentProps, nextProps), // check props
* isIgnorable: function (propertyValue, propertyKey), // check if property item is ignorable
* unCursor: function (cursor) // convert from cursor to object
* }
* ```
*
Expand Down Expand Up @@ -184,105 +185,198 @@ function factory (initialOptions) {
var _classDecorator = initialOptions.classDecorator || identity;
var _cached = cached.withDefaults(_shouldComponentUpdate);

var CreatedComponent = ComponentCreatorFactory(_classDecorator);

/**
* Activate debugging for components. Will log when a component renders,
* the outcome of `shouldComponentUpdate`, and why the component re-renders.
* Create components for functional views, with an attached local class decorator.
* Omniscient uses a `React.createClass()` internally to create an higher order
* component to attach performance boost and add some syntactic sugar to your
* components. Sometimes third party apps need to be added as decorator to this
* internal class. For instance Redux or Radium.
* This create factory behaves the same as normal Omniscient.js component
* creation, but with the additional first parameter for class decorator.
*
* ### Example
* ```js
* Search>: shouldComponentUpdate => true (cursors have changed)
* Search>: render
* SearchBox>: shouldComponentUpdate => true (cursors have changed)
* SearchBox>: render
* The API of Omniscient is pretty simple, you create a Stateless React Component
* but memoized with a smart implemented `shouldComponentUpdate`.
*
* The provided `shouldComponentUpdate` handles immutable data and cursors by default.
* It also falls back to a deep value check if passed props isn't immutable structures.
*
* You can use an Omniscient component in the same way you'd use a React Stateless Function,
* or you can use some of the additional features, such as string defined display name and
* pass in life cycle methods. These are features normally not accessible for vanilla
* Stateless React Components.
*
* If you simply pass one cursor, the cursor will be accessible on the
* `props.cursor` accessor.
*
* #### Decorating class components
* ```jsx
* // Some third party libraries requires you to decorate the
* // React class, not the created component. You can do that
* // by creating a decorated component factory
* var someDecorator = compose(Radium, function (Component) {
* var DecoratedComponent = doSomething(Component);
* return DecoratedComponent;
* });
* var Component = component.classDecorator(someDecorator, function (props) {
* // ... some implementation
* });
*
* React.render(<Component />, mountingPoint);
* ```
*
* @example omniscient.debug(/Search/i);
* Also works by creating a component factory:
*
* ```jsx
* var someDecorator = compose(Radium, function (Component) {
* var DecoratedComponent = doSomething(Component);
* return DecoratedComponent;
* });
* var newFactory = component.classDecorator(someDecorator);
* var Component = newFactory(function (props) {
* // ... some implementation
* });
*
* React.render(<Component />, mountingPoint);
* ```
*
* @param {RegExp} pattern Filter pattern. Only show messages matching pattern
* @param {Function} classDecorator Decorator to use for internal class (e.g. Redux connect, Radium)
* @param {String} [displayName] Component's display name. Used when debug()'ing and by React
* @param {Array|Object} [mixins] React mixins. Object literals with functions, or array of object literals with functions.
* @param {Function} [render] Stateless component to add memoization on.
*
* @module omniscient.debug
* @returns {Immstruct}
* @property {Function} shouldComponentUpdate Get default shouldComponentUpdate
* @module omniscient
* @returns {Component|Function}
* @api public
*/
ComponentCreator.debug = debugFn;
ComponentCreator.cached = _cached;
ComponentCreator.shouldComponentUpdate = _shouldComponentUpdate;
return ComponentCreator;

function ComponentCreator (displayName, mixins, render) {
var options = createDefaultArguments(displayName, mixins, render);
var methodStatics = pickStaticMixins(options.mixins);

var componentObject = {
displayName: options.displayName || options.render.name,
mixins: options.mixins,
render: function render () {
if (debug) debug.call(this, 'render');
// If `props['__singleCursor']` is set a single cursor was passed
// to the component, pick it out and pass it.
var input = this.props[_hiddenCursorField] || this.props;
this.cursor = this.props[_hiddenCursorField];
return options.render.call(this, input);
}
};

if (methodStatics) {
componentObject.statics = methodStatics;
removeOldStaticMethods(options.mixins);
CreatedComponent.classDecorator = function (classDecorator) {
var shouldPartiallyApply = arguments.length === 1;
if (shouldPartiallyApply) {
return ComponentCreatorFactory(classDecorator);
}
return ComponentCreatorFactory(classDecorator).apply(null, toArray(arguments).slice(1));
};
return CreatedComponent;

var Component = _classDecorator(React.createClass(componentObject));
function ComponentCreatorFactory (passedClassDecorator) {

/**
* Invoke component (rendering it)
* Activate debugging for components. Will log when a component renders,
* the outcome of `shouldComponentUpdate`, and why the component re-renders.
*
* ### Example
* ```js
* Search>: shouldComponentUpdate => true (cursors have changed)
* Search>: render
* SearchBox>: shouldComponentUpdate => true (cursors have changed)
* SearchBox>: render
* ```
*
* @param {String} displayName Component display name. Used in debug and by React
* @param {Object} props Properties (triggers update when changed). Can be cursors, object and immutable structures
* @param {Object} ...rest Child components (React elements, scalar values)
* @example omniscient.debug(/Search/i);
*
* @module Component
* @returns {ReactElement}
* @param {RegExp} pattern Filter pattern. Only show messages matching pattern
*
* @module omniscient.debug
* @returns {Immstruct}
* @api public
*/
var create = function (key, props) {
var _props;
var inputCursor;
var children;

if (typeof key === 'object') {
props = key;
key = void 0;
ComponentCreator.debug = debugFn;
ComponentCreator.cached = _cached;
ComponentCreator.shouldComponentUpdate = _shouldComponentUpdate;

return ComponentCreator;

function ComponentCreator (displayName, mixins, render) {
var options = createDefaultArguments(displayName, mixins, render);
var methodStatics = pickStaticMixins(options.mixins);

var componentObject = {
displayName: options.displayName || options.render.name,
mixins: options.mixins,
render: function render () {
if (debug) debug.call(this, 'render');
// If `props['__singleCursor']` is set a single cursor was passed
// to the component, pick it out and pass it.
var input = this.props[_hiddenCursorField] || this.props;
this.cursor = this.props[_hiddenCursorField];
return options.render.call(this, input);
}
};

if (methodStatics) {
componentObject.statics = methodStatics;
removeOldStaticMethods(options.mixins);
}

children = flatten(sliceFrom(arguments, props).filter(_isNode));

// If passed props is a signle cursor we move it to `props[_hiddenCursorField]`
// to simplify should component update. The render function will move it back.
// The name '__singleCursor' is used to not clash with names of user passed properties
if (_isCursor(props) || _isImmutable(props)) {
inputCursor = props;
_props = {};
_props[_hiddenCursorField] = inputCursor;
} else {
_props = assign({}, props);
}

if (key) {
_props.key = key;
var Component = passedClassDecorator(React.createClass(componentObject));

/**
* Invoke component (rendering it)
*
* @param {String} displayName Component display name. Used in debug and by React
* @param {Object} props Properties (triggers update when changed). Can be cursors, object and immutable structures
* @param {Object} ...rest Child components (React elements, scalar values)
*
* @module Component
* @returns {ReactElement}
* @api public
*/
var create = function (keyOrProps, propsOrPublicContext, ReactUpdateQueue) {
// After stateless arrow functions was allowed as components, react will instantiate
// the `create` function if it has a prototype. We are passed `props`, `publicContext`
// and `ReactUpdateQueue`.
// https://github.com/facebook/react/blob/88bae3fb73511893519195e451c56896463f669b/src/renderers/shared/reconciler/ReactCompositeComponent.js#L154-L171
if (typeof ReactUpdateQueue == 'object' && !_isNode(ReactUpdateQueue)) {
var publicProps = keyOrProps,
publicContext = propsOrPublicContext;
return new Component(publicProps, publicContext, ReactUpdateQueue);
}

var key = keyOrProps,
props = propsOrPublicContext;

if (typeof key === 'object') {
props = key;
key = void 0;
}

var children = flatten(sliceFrom(arguments, props).filter(_isNode));

var _props,
inputCursor;

// If passed props is a signle cursor we move it to `props[_hiddenCursorField]`
// to simplify should component update. The render function will move it back.
// The name '__singleCursor' is used to not clash with names of user passed properties
if (_isCursor(props) || _isImmutable(props)) {
inputCursor = props;
_props = {};
_props[_hiddenCursorField] = inputCursor;
} else {
_props = assign({}, props);
}

if (key) {
_props.key = key;
}

if (children.length) {
_props.children = children;
}

return React.createElement(Component, _props);
};

if (methodStatics) {
create = assign(create, methodStatics);
}

if (!!children.length) {
_props.children = children;
}
create.type = Component;

return React.createElement(Component, _props);
};

if (methodStatics) {
create = assign(create, methodStatics);
return create;
}

return create;
}

function debugFn (pattern, logFn) {
Expand Down
Loading

0 comments on commit 4fefa98

Please sign in to comment.