UNPKG

solrkit

Version:

![Build Status](https://travis-ci.org/garysieling/solrkit.svg?branch=master) ![Dependencies](https://david-dm.org/garysieling/solrkit/status.svg)

92 lines 3.25 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); var react_1 = require("react"); var _ = require("lodash"); function databind(event, ds, render, transition) { return function () { return (React.createElement(Bound, { event: event, dataStore: ds, render: render, transition: transition })); }; } exports.databind = databind; var Bound = (function (_super) { __extends(Bound, _super); function Bound(props) { var _this = _super.call(this, props) || this; _this.state = { data: undefined, paging: undefined }; (props.event || props.dataStore.onQuery).call(props.dataStore, function (data, paging) { _this.setState({ data: data, paging: paging }); }); return _this; } Bound.prototype.transition = function (args) { if (this.props.transition) { if (this.props.transition(args)) { return; } } var currentParams = this.props.dataStore.getCurrentParameters(); var newParams = _.extend({}, currentParams, args, { type: 'QUERY' }); if (args.facets) { newParams.facets = _.extend({}, currentParams.facets, args.facets); } this.props.dataStore.stateTransition(newParams); }; Bound.prototype.componentDidMount = function () { if (this.props.autoload) { this.transition(this.props.autoload); } }; Bound.prototype.getChildContext = function () { return { searchState: this.props.dataStore.getCurrentParameters(), transition: this.transition.bind(this) }; }; Bound.prototype.render = function () { return (this.props.render(this.state.data || [], this.state.paging || { numFound: 0, start: 0, pageSize: 10 })); }; Bound.childContextTypes = { transition: react_1.PropTypes.func, searchState: react_1.PropTypes.object }; Bound.contextTypes = { router: react_1.PropTypes.object }; return Bound; }(React.Component)); exports.Bound = Bound; var DataBind = (function (_super) { __extends(DataBind, _super); function DataBind() { return _super !== null && _super.apply(this, arguments) || this; } DataBind.prototype.render = function () { return (React.createElement("div", null, this.props.children)); }; return DataBind; }(React.Component)); exports.DataBind = DataBind; //# sourceMappingURL=DataBinding.js.map