Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .babelrc

This file was deleted.

23 changes: 0 additions & 23 deletions .babelrc.js

This file was deleted.

11 changes: 0 additions & 11 deletions .flowconfig

This file was deleted.

10 changes: 4 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
node_modules
*.log
lib
.cache
dist
coverage
node_modules/
/*.js
/*.d.ts
yarn-error.log
8 changes: 8 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/node_modules/
/src/
/img/
tsconfig.json
jest.config.js
package-lock.json
yarn.lock
yarn-error.log
3 changes: 0 additions & 3 deletions .prettierrc

This file was deleted.

13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

19 changes: 0 additions & 19 deletions LICENSE

This file was deleted.

86 changes: 80 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,87 @@
<div align="center">
<br><br><br><br><br>
<img src="https://raw.githubusercontent.com/thejameskyle/unstated/master/logo.png" alt="Unstated Logo" width="400">
<br><br><br><br><br><br><br><br>
<br><br><br><br>
<img src="https://raw.githubusercontent.com/shadowwalker/unstated/typescript/img/logo.png" alt="Unstated Logo" width="400"/>
<br>
<h2 style="border-bottom: none;">Rewritten in Typescript</h2>
<br><br><br><br>
</div>

# Unstated

> State so simple, it goes without saying
> State so simple, it goes without saying. Now with typescript support.

## Highlight Typescript Support

### Typecheck Errors

![](https://github.com/shadowwalker/unstated/blob/typescript/img/typecheck-error-empty-container-generic.png?raw=true)

![](https://github.com/shadowwalker/unstated/blob/typescript/img/typecheck-error-empty-inject.png?raw=true)

![](https://github.com/shadowwalker/unstated/blob/typescript/img/typecheck-error-empty-to.png?raw=true)

### Type Inference

![](https://github.com/shadowwalker/unstated/blob/typescript/img/typecheck-infer-subscribe-children.png?raw=true)

![](https://github.com/shadowwalker/unstated/blob/typescript/img/typecheck-infer-unstated.png?raw=true)

## New Feature

### unstated HOC

``` typescript
import unstated from 'unstated'
```

`unstated` is a HOC that works like `connect` in `react-redux`, it makes things simple to work with dummy component.

``` typescript
interface ICounterProps {
count: number
decrement: () => void
increment: () => void
}

const Counter = ({count, decrement, increment}: ICounterProps) => (
<div>
<span>{count}</span>
<button onClick={() => decrement()}>-</button>
<button onClick={() => increment()}>+</button>
</div>
)

const UnstatedCounter = unstated(CounterContainer,
counter => ({
count: counter.state.count,
decrement: counter.decrement,
increment: counter.increment
})
)(Counter)
```

`unstated` takes two arguments, the first is a single or an array of container class or container, the second is an optional map to props function.

``` typescript
// without map to props function
// container instance could be accessed as first letter lower cased key in props
const UnstatedComponent = unstated(Container)(Component)
const Component = ({ container }) => (... ...)

// with map to props
const UnstatedComponent = unstated(Container, container => ({
fooProp = container.state.fooState,
barFuncProp = container.barFunc
}))(Component)

// multiple containers
const UnstatedComponent = unstated([C1,C2], (c1,c2) => ({
foo1 = c1.state.fooState,
barFuncProp2 = c1.barFunc,
fooProp2 = c2.state.fooState,
barFuncProp2 = c2.barFunc
}))(Component)
```

## Installation

Expand All @@ -17,7 +92,6 @@ yarn add unstated
## Example

```jsx
// @flow
import React from 'react';
import { render } from 'react-dom';
import { Provider, Subscribe, Container } from 'unstated';
Expand Down Expand Up @@ -516,4 +590,4 @@ render(
## Related

- [unstated-debug](https://github.com/sindresorhus/unstated-debug) - Debug your Unstated containers with ease

83 changes: 0 additions & 83 deletions __tests__/unstated.js

This file was deleted.

98 changes: 0 additions & 98 deletions __tests__/unstated.tsx

This file was deleted.

Loading