Skip to content

Commit

Permalink
refactor(BareBones): extract query logic into its own class
Browse files Browse the repository at this point in the history
  • Loading branch information
Adnan Asani committed Dec 16, 2017
1 parent 020ed51 commit 2d00bd8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
49 changes: 44 additions & 5 deletions src/BareBones.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
import * as React from 'react';

function search<T, U>(
value: T,
extensions: Array<BareBones.FunctionalExtensions<U>>
): any {}

interface QueryProps<T> {
children: (x: any) => React.ReactNode;
extensions: Array<BareBones.FunctionalExtensions<T>>;
maxResults?: number;
}

interface QueryState {}

// Generic class to be used on the bare-bones version, and the "full package" version
class Query<T> extends React.PureComponent<QueryProps<T>, QueryState> {
query = (value: string) => {
search<string, T>(value, this.props.extensions).then((results: any) => {});
};
render() {
return (
<div>
{this.props.children({
onChange: this.query,
})}
</div>
);
}
}

export default class BareBones<T> extends React.PureComponent<
BareBones.Props<T>,
BareBones.State<T>
Expand All @@ -9,11 +38,21 @@ export default class BareBones<T> extends React.PureComponent<
};
render() {
return (
<div>
{this.props.children({
results: [],
})}
</div>
<Query
extensions={this.props.extensions}
maxResults={this.props.maxResults}
>
{({ onChange }) => {
return (
<div>
<input onChange={onChange} />
{this.props.children({
results: [],
})}
</div>
);
}}
</Query>
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Omnibar from './Omnibar';
import BareBones from './BareBones';
import { command } from './decorators';
import { withVoice } from './hoc';

export default Omnibar;

export { command, withVoice };
export { command, withVoice, BareBones };
1 change: 1 addition & 0 deletions typings/bare-bones.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ declare namespace BareBones {
interface Props<T> {
children: <T>(e: T) => React.ReactNode;
extensions: Array<BareBones.FunctionalExtensions<T>>;
maxResults?: number;
}

interface State<T> {
Expand Down

0 comments on commit 2d00bd8

Please sign in to comment.