UNPKG

solrkit

Version:

![Build Status](https://travis-ci.org/garysieling/solrkit.svg?branch=master) ![Dependencies](https://david-dm.org/garysieling/solrkit/status.svg) UI Components for Solr, using TypeScript + React

85 lines 3.3 kB
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 __()); }; })(); import * as React from 'react'; import { PropTypes } from 'react'; import * as _ from 'lodash'; function databind(event, ds, render) { return function () { return (React.createElement(Bound, { event: event, dataStore: ds, render: render })); }; } var Bound = (function (_super) { __extends(Bound, _super); function Bound(props) { var _this = _super.call(this, props) || this; _this.state = { data: undefined, paging: undefined }; // This needs to happen early props.event.call(props.dataStore, function (data, paging) { _this.setState({ data: data, paging: paging }); }); return _this; } Bound.prototype.transition = function (args) { var currentParams = this.props.dataStore.getCurrentParameters(); var newParams = Object.assign({}, currentParams, args); if (args.facets) { newParams.facets = Object.assign({}, currentParams.facets, args.facets); } // TODO - should handle different classes of route var page = (newParams.start || 0) / this.props.dataStore.getCoreConfig().pageSize + 1; var facets = ''; if (newParams.facets) { facets = '?' + _.map(newParams.facets, function (k, v) { return v + '=' + (_.isArray(k) ? k.join(',') : k); }).join('&'); } this.context.router.history.push('/' + this.props.dataStore.getCoreConfig().prefix + '/' + newParams.query + '/' + page + facets); this.props.dataStore.stateTransition(newParams); }; Bound.prototype.getChildContext = function () { return { searchState: this.props.dataStore.getCurrentParameters(), transition: this.transition.bind(this) }; }; Bound.prototype.render = function () { // TODO these need to be named or something if (!this.state.data) { return null; } return (this.props.render(this.state.data || [], this.state.paging)); }; Bound.childContextTypes = { transition: PropTypes.func, searchState: PropTypes.object }; Bound.contextTypes = { router: PropTypes.object }; return Bound; }(React.Component)); 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)); export { DataBind, Bound, databind }; //# sourceMappingURL=DataBinding.js.map