Skip to content

Commit

Permalink
docs: add guide
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed Jan 14, 2020
1 parent 14fff88 commit 7dd10c9
Show file tree
Hide file tree
Showing 12 changed files with 521 additions and 23 deletions.
64 changes: 59 additions & 5 deletions docs/.vuepress/config.js
@@ -1,12 +1,66 @@
module.exports = {
theme: 'yuu',
themeConfig: {
yuu: {
defaultDarkTheme: true,
defaultColorTheme: 'blue',
colorThemes: ['blue']
repo: 'crimx/retux',
// edit footer
docsDir: 'docs',
editLinks: true,
locales: {
'/': {
// label for this locale in the language dropdown
label: 'English',
// Aria Label for locale in the dropdown
ariaLabel: 'Languages',
// text for the edit-on-github link
editLinkText: 'Edit this page on GitHub',
// config for Service Worker
serviceWorker: {
updatePopup: {
message: 'New content is available.',
buttonText: 'Refresh'
}
},
nav: [{ text: 'Guide', link: '/guide/' }],
sidebar: [
{
title: 'Guide', // required
path: '/guide/', // optional, which should be a absolute path.
collapsable: false, // optional, defaults to true
sidebarDepth: 1, // optional, defaults to 1
children: ['/guide/', '/guide/motivation', '/guide/core-concepts']
}
]
}
}
},
plugins: [
[
'@vuepress/pwa',
{
serviceWorker: true,
updatePopup: true
}
]
],
// prettier-ignore
head: [
['link', {rel: "apple-touch-icon", sizes: "57x57", href: "/apple-icon-57x57.png"}],
['link', {rel: "apple-touch-icon", sizes: "60x60", href: "/apple-icon-60x60.png"}],
['link', {rel: "apple-touch-icon", sizes: "72x72", href: "/apple-icon-72x72.png"}],
['link', {rel: "apple-touch-icon", sizes: "76x76", href: "/apple-icon-76x76.png"}],
['link', {rel: "apple-touch-icon", sizes: "114x114", href: "/apple-icon-114x114.png"}],
['link', {rel: "apple-touch-icon", sizes: "120x120", href: "/apple-icon-120x120.png"}],
['link', {rel: "apple-touch-icon", sizes: "144x144", href: "/apple-icon-144x144.png"}],
['link', {rel: "apple-touch-icon", sizes: "152x152", href: "/apple-icon-152x152.png"}],
['link', {rel: "apple-touch-icon", sizes: "180x180", href: "/apple-icon-180x180.png"}],
['link', {rel: "icon", type: "image/png", sizes: "192x192" , href: "/android-icon-192x192.png"}],
['link', {rel: "icon", type: "image/png", sizes: "32x32", href: "/favicon-32x32.png"}],
['link', {rel: "icon", type: "image/png", sizes: "96x96", href: "/favicon-96x96.png"}],
['link', {rel: "icon", type: "image/png", sizes: "16x16", href: "/favicon-16x16.png"}],
['link', {rel: "manifest", href: "/manifest.json"}],
['meta', {name: "msapplication-TileColor", content: "#ffffff"}],
['meta', {name: "msapplication-TileImage", content: "/ms-icon-144x144.png"}],
['meta', {name: "theme-color", content: "#007acc"}]
],
locales: {
'/': {
lang: 'en-US',
Expand Down
Binary file modified docs/.vuepress/public/favicon-16x16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/.vuepress/public/favicon-32x32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/.vuepress/public/favicon.ico
Binary file not shown.
2 changes: 2 additions & 0 deletions docs/.vuepress/styles/palette.styl
@@ -0,0 +1,2 @@
$accentColor = #1297E0
$badgeTipColor = #2196f3
8 changes: 4 additions & 4 deletions docs/README.md
Expand Up @@ -6,13 +6,13 @@ tagline: Minimalist declarative type-safe(strongly-typed) scalable Redux archite
actionText: Get Started →
actionLink: /guide/
features:
- title: Minimalist
- title: ☕️ Minimalist
details: Leveraging advanced features of TypeScript Retux reduces boilerplate code with better type-inferring and auto-completion.
- title: Declarative
- title: 📃 Declarative
details: Action-First instead of Action-Creator-Fisrt desgin results in code that is clean and easy to read for new contributors and future-self.
- title: Type-safe
- title: 🛡 Type-safe
details: Retux enforces strict typings. With the utilities in Retux you will never lose the strictness of typings while enjoying great flexibility.
- title: Scalable
- title: 📈 Scalable
details: A Retux module can be easily split into isomorphic sub-modules. Retux can also optionly leverage the power of meta-programming on modern engine for further performance boost.
footer: MIT Licensed | Copyright © 2019-present CRIMX
---
File renamed without changes
90 changes: 90 additions & 0 deletions docs/guide/README.md
@@ -0,0 +1,90 @@
# Introduction

Retux is a TypeScript Redux architecture which aims for reducing boilerplate code while maintaining better type-inferring, readability and scalability.

The `retux` package contains mostly type helpers with some utility-functions for working with Redux.

## Installation

Retux is meant to work with Redux so you have to install both:

```bash
# NPM
npm install --save redux retux

# Yarn
yarn add redux retux
```

::: warning
Retux does not offer precompiled UMD package since it is mainly for TypeScript projects.
:::

## Basic Example

The best part of Retux is that you can always start with the basic form of Retux then easily perform small refactoring along the way as the project scales.

Here is a typical Retux module with 4 exports:

```typescript
import { CreateActionCatalog, ActionHandlers } from 'retux'

// All actions of a module are defined here.
// This is the core of Retux design.
// Other infomation will be extracted from Action Catalog.
// It can also be easily splited as it scales.
export type ActionCatalog = CreateActionCatalog<{
INCREMENT: {
payload: {
/** default 1 */
step?: number
}
}
DECREMENT: {
payload: {
/** default 1 */
step?: number
}
}
}>

export const initState = {
count: 0
}

export type State = Readonly<typeof initState>

// Action Handlers can be easily splited as it scales.
export const actionHandlers: ActionHandlers<State, ActionCatalog> = {
// Any missing or mistyped action will be caught by ts compiler.
INCREMENT: (state, { payload: { step = 1 } }) => ({
count: state.count + step
}),
DECREMENT: (state, { payload: { step = 1 } }) => ({
count: state.count - step
})
}

// Then at the store root:

import { createStore } from 'redux'
import { createReducer, createActionCreators } from 'retux'

const reducer = createReducer(initState, counterActionHandlers)

const store = createStore(reducer)

store.subscribe(() => console.log(store.getState()))

// Actions are strongly typed. Any mistyped name is caught by ts compiler.
store.dispatch({ type: 'INCREMENT' })

// Or if you prefer action creators
const action = createActionCreators(actionHandlers)
// Payload and meta are also strongly typed with the action type.
store.dispatch(action.DECREMENT({ step: 10 }))
```

See [examples](https://github.com/crimx/retux/tree/master/examples) for more realistic code.

Retux introduces the concept of `ActionCatalog` which has all the readability benefits from [Flux constant style](https://redux.js.org/recipes/reducing-boilerplate#actions) without adding any boilerplate code. More details on the power of `ActionCatalog` see [Core Concepts](./core-concepts.md) of Retux.

0 comments on commit 7dd10c9

Please sign in to comment.