• Stars
    star
    266
  • Rank 154,103 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An Isomorphic MVC Framework supports both SSR and CSR

react-imvc v2.0

Build Status dependencies Status PRs-welcome

NPM

2.0 升级指南

1.0 仓库和文档地址

MVC 三者都是 Isomorphic,既是服务端 MVC,也是浏览器端 MVC。

react-imvc 是 isomorphic mvc 的 react 实现,它是一个 Web 框架。通过 react-imvc,我们可以更便利地实现同构 Web 应用的开发。

用法示例:

点击访问详细文档地址:Documents

react-imvc 的作用和特性

  • 一条命令启动完整的开发环境
  • 一条命令编译和构建源代码
  • 一份代码,既可以在 node.js 做服务端渲染(SSR),也可以在浏览器端复用后继续渲染(CSR & SPA)
  • 既是多页应用,也是单页应用,还可以通过配置自由切换两种模式,用「同构应用」打破「单页 VS 多页」的两难抉择
  • 构建时可以生成一份 hash history 模式的静态文件,当做普通单页应用的入口文件(如 DEMO 所示)
  • 构建时可以根据路由切割代码,按需加载 js 文件
  • 支持在 IE9 及更高版本浏览器里,使用包括 async/await 在内的 ES2015+ 语言新特性
  • 丰富的生命周期,让业务代码有更清晰的功能划分
  • 内部自动解决在浏览器端复用服务端渲染的 html 和数据,无缝过渡
  • 好用的同构方法 fetch、redirect 和 cookie 等,贯通前后端的请求、重定向和 cookie 等操作
  • 还有更多隐藏特性,在等待你去发掘……

安装 react-imvc

react-imvc 是一个整体解决方案,包括服务端和客户端,所以必须从 npm 或 yarn 里下载到 package.json 里。

npm install --save react react-dom react-imvc

使用 react-imvc 开发 Hello World

第一步:添加 npm scripts 任务

在你的 package.json 里添加 npm scripts 如下命令:

{
    "scripts": {
        "start": "react-imvc start",
        "build": "react-imvc build",
        "test": "react-imvc test"
    }
}

第二步:添加源代码目录 src/ 和路由文件 index.js

在 package.json 所在的目录下,新建一个文件夹,名称为 src

在 src 文件夹里新增 index.js 入口文件,添加一组 {path, controller} 的路由配置

// src/index.js
export default [
    {
        path: '/',
        controller: () => import('./home/Controller')
    }
]

第三步:编写每个页面的 MVC 结构

每个页面必须是一个包含 controller.js 的文件夹,其中 controller.js 是页面的入口文件

// src/home/Controller
import Controller from 'react-imvc/controller' // 加载 react-imvc controller 控制器
import React from 'react'

export default class Home extends Controller { // 继承它,编写你的控制器逻辑
    View = View // 将 react 组件赋值给控制器的 View 属性
}

function View() {
    return (
        <h1>Hello React-IMVC</h1>
    )
}

第四步:npm start 启动应用

在命令行输入 npm start,然后打开 http://localhost:3000,将看到 Hello React-IMVC

查看页面源代码,可以看到服务端渲染的内容。

欢迎提 Issue 和 Pull Request

More Repositories

1

react-lite

An implementation of React v15.x that optimizes for small script size
JavaScript
1,726
star
2

factor-network

A simple factor network implementation written by JavaScript
JavaScript
542
star
3

Lucifier129.github.io

Lucifier129.github.io
JavaScript
410
star
4

Isomorphism-react-todomvc

Isomorphism javascript of todomvc powered by react and express
JavaScript
196
star
5

pull-element

Lightweight, high-performance and smooth pull element effect that support all directions
JavaScript
174
star
6

bistate

A state management library for React combined immutable, mutable and reactive mode
TypeScript
121
star
7

flappy-bird

flappy-bird game with time travel written by react and create-react-app
JavaScript
95
star
8

promise-aplus-impl

A simple implementation of Promise /A+ Spec
JavaScript
91
star
9

simple-machine-learning-demo

simple machine learning demo
JavaScript
64
star
10

relite

a redux-like library for managing state with simpler api
TypeScript
57
star
11

rxjs-react

make your react-component become reactive with rxjs
JavaScript
55
star
12

isomorphic-cnode

isomorphic-cnode
JavaScript
54
star
13

language-implementation-patterns

《编程语言实现模式》的相关练习
HTML
40
star
14

rust-ray-tracing-demo

The rust implementation of <Ray Tracing in One Weekend>
JavaScript
40
star
15

fetch-imgs

40 行 node.js 代码实现简易的图片爬虫
JavaScript
39
star
16

react-stateful

A simple implementation of React-State-Hook and React-Effect-Hook to show how React-Hooks work
JavaScript
34
star
17

react-use-setup

Implement the mechanism of Vue 3.0 Composition API for React based on React Hooks
TypeScript
30
star
18

coproduct

A small library aims to improve better tagged-unions/discriminated-unions supporting for TypeScript
TypeScript
29
star
19

create-app

configuring once, rendering both client and server.
TypeScript
28
star
20

the-super-tiny-jsx-compiler

the-super-tiny-jsx-compiler
JavaScript
23
star
21

react-imvc-template

react-imvc-template
JavaScript
21
star
22

functional-di

Dependency injection in functional style
TypeScript
18
star
23

next-mvc

An isomorphic mvc framework based on next.js, react, redux and immer
JavaScript
18
star
24

pure-model

A framework for writing model-oriented programming
TypeScript
16
star
25

jiandanimgs

煎蛋网高质量妹子图无广告版
JavaScript
15
star
26

monodic

Monorepo: 多项目单仓库工程管理方案
TypeScript
14
star
27

coeffect

An effect-management library for React
TypeScript
14
star
28

vdom-engine

Rethink and redesign React for Web
JavaScript
14
star
29

youmightnotneedflux

you might not need flux
JavaScript
13
star
30

gvs

Global variables sniffer
JavaScript
13
star
31

learn-webgl

some demos for learning webgl
JavaScript
13
star
32

jplus

jQuery指令插件
JavaScript
13
star
33

refer

redux-like library for handling global state on functional style
JavaScript
12
star
34

react-props

inject props to react component for high performance rendering
JavaScript
11
star
35

create-react-store

Create reactive stores for React App
TypeScript
10
star
36

react-hooks-demo

A demo based on react-hooks for show-case
JavaScript
10
star
37

training

9
star
38

graphql-dynamic

Dynamic, schema-less, directive-driven GraphQL
JavaScript
8
star
39

react-director

es2016-base router for react on decorator style
JavaScript
8
star
40

todo-imvc

todo list app powered by react-imvc
JavaScript
8
star
41

refer-dom

mvvm library base on virtural-dom and flux pattern
JavaScript
7
star
42

fe-starter

frontend-starter
JavaScript
7
star
43

costate

A state management library for react inspired by vue 3.0 reactivity api and immer
TypeScript
7
star
44

react-core-unit-testing

Use to implement your own reactjs
JavaScript
6
star
45

react-page-template

react 多页应用的模板,支持服务端渲染
JavaScript
6
star
46

umd-pack

a tool for creating library bundle file in UMD-style(forked from create-react-app)
JavaScript
5
star
47

sukkula

A state-management library aims to combine the best parts of redux and rxjs
JavaScript
5
star
48

create-react-store-todo-app

A Todo App demo powered by create-react-store
CSS
5
star
49

Agent

代理模式:将函数调用转化为配置模式
JavaScript
5
star
50

retour

an easy way to create isomorphic web app, render your page on both server-side and client-side
JavaScript
4
star
51

rxjs-animation-demo

A demo for rxjs animation
TypeScript
4
star
52

costate-examples

online demo
JavaScript
3
star
53

bistate-examples

demos for https://github.com/Lucifier129/bistate
JavaScript
3
star
54

slidev-slides

Slides via slidev
TypeScript
3
star
55

jade-incubator

Some interesting projects for POC, don't use them in production!
TypeScript
3
star
56

next-mvc-cnode

cnode web app with SSR powered by next-mvc
CSS
2
star
57

rocket-todo-app

A simple todo app powered by rocket and react
Rust
2
star
58

process

javascript 流程管理机制
JavaScript
2
star
59

jMin.js

自己写的手机端微型-类jQuery工具库
JavaScript
2
star
60

react-mvc-component

React Component in MVC style
2
star
61

isomorphism-react-file-system

同构react文件系统(娱乐项目)
JavaScript
1
star
62

jsx-template

simple jsx-template
JavaScript
1
star
63

observe.js

观察对象的属性,当它变化时,调用指定函数(更新:支持事件命名空间)。
JavaScript
1
star
64

webpack-workflow

webpack workflow for SPA
JavaScript
1
star
65

fe-tutorial

1
star
66

rx-view

react meets rxjs
JavaScript
1
star
67

static-server-toy

build static server using node.js in some different style
JavaScript
1
star
68

react-use-setup-examples

JavaScript
1
star
69

Msg

订阅者/发布者模式,自定义消息类型的工具库
JavaScript
1
star
70

esnext-framework

探究基于将来版本的 ECMAScript 框架模式
JavaScript
1
star