├── .eslintignore ├── .eslintrc.js ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .huskyrc ├── .npmrc ├── .prettierignore ├── .prettierrc ├── .travis.yml ├── README.md ├── dist ├── mini-mvvm.js └── mini-vdom.js ├── lerna.json ├── package-lock.json ├── package.json ├── packages ├── mini-mvvm │ ├── .npmrc │ ├── README.md │ ├── __tests__ │ │ └── lifecycle.test.ts │ ├── index.html │ ├── jest.config.js │ ├── package.json │ ├── rollup.config.js │ ├── src │ │ ├── common │ │ │ ├── EventEmitter.ts │ │ │ ├── enums.ts │ │ │ └── utils.ts │ │ ├── core │ │ │ ├── BaseMVVM.ts │ │ │ └── MVVM.ts │ │ ├── dev.scss │ │ ├── dev.ts │ │ └── lib │ │ │ ├── Compile │ │ │ ├── AST.ts │ │ │ ├── Compile.ts │ │ │ ├── index.ts │ │ │ └── parsers │ │ │ │ ├── parseAttrs.ts │ │ │ │ ├── parseEvents.ts │ │ │ │ ├── parseFor.ts │ │ │ │ ├── parseIf.ts │ │ │ │ ├── parseModel.ts │ │ │ │ └── parseProps.ts │ │ │ ├── Dep.ts │ │ │ ├── ELifeCycle.ts │ │ │ ├── Observer.ts │ │ │ └── Watcher.ts │ └── tsconfig.json └── mini-vdom │ ├── .npmrc │ ├── README.md │ ├── __tests__ │ ├── h.test.ts │ ├── hook.test.ts │ └── patch.test.ts │ ├── index.html │ ├── jest.config.js │ ├── package.json │ ├── rollup.config.js │ ├── src │ ├── dev.scss │ ├── dev.ts │ ├── index.ts │ ├── lib │ │ ├── VNode.ts │ │ ├── h.ts │ │ ├── hooks.ts │ │ ├── modules │ │ │ ├── attrs.ts │ │ │ ├── events.ts │ │ │ └── props.ts │ │ └── patch.ts │ └── utils │ │ └── index.ts │ └── tsconfig.json └── scripts └── build.sh /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | build 4 | __tests__ 5 | scripts 6 | *.d.ts 7 | *.html 8 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: '@nosaid/eslint-config-for-typescript', 3 | rules: { 4 | '@typescript-eslint/ban-types': 'off', 5 | '@typescript-eslint/explicit-module-boundary-types': 'off', 6 | 'no-case-declarations': 'off' 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: ci 5 | 6 | on: 7 | push: 8 | branches: [master] 9 | pull_request: 10 | branches: [master] 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v2 18 | - name: Use Node.js 14 19 | uses: actions/setup-node@v2 20 | with: 21 | node-version: 14 22 | - run: npm ci 23 | - run: npm run bootstrap 24 | - run: npm run build:lp 25 | - run: npm run lint 26 | - run: npm test 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | .DS_Store 64 | 65 | # package-lock.json 66 | 67 | # 只保留顶部的 dist 68 | /*/**/dist/ 69 | -------------------------------------------------------------------------------- /.huskyrc: -------------------------------------------------------------------------------- 1 | { 2 | "hooks": { 3 | "pre-commit": "npm run lint" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | registry=https://registry.npm.taobao.org 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "none", 4 | "tabWidth": 4, 5 | "endOfLine": "auto", 6 | "printWidth": 120, 7 | "bracketSpacing": true, 8 | "arrowParens": "avoid", 9 | "overrides": [ 10 | { 11 | "files": ["*.yaml", "*.yml", "package.json"], 12 | "options": { 13 | "singleQuote": false, 14 | "tabWidth": 2 15 | } 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '10.16.0' 4 | install: 5 | - npm install 6 | - npm run bootstrap 7 | script: 8 | - npm run build:lp 9 | - npm run lint 10 | - npm test 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mini-mvvm 2 | 3 | [](https://www.npmjs.com/package/mini-mvvm) 4 | [](https://www.npmjs.com/package/mini-mvvm) 5 | [](https://github.com/shalldie/mini-mvvm/actions) 6 | 7 | A mini mvvm lib with [virtual dom - mini-vdom](https://github.com/shalldie/mini-mvvm/tree/master/packages/mini-vdom). 8 | 9 | 基于 [virtual dom - mini-vdom](https://github.com/shalldie/mini-mvvm/tree/master/packages/mini-vdom) 的轻量级 mvvm 库 >\_<#@! 10 | 11 | 适用于 ui 组件的构建依赖或小型项目,如果项目比较复杂,也许一个更加成熟的 mvvm 框架及其生态更适合你 🤠🤠 12 | 13 | ## Installation 14 | 15 | npm install mini-mvvm --save 16 | 17 | 包含了 `.d.ts` 文件,用起来毫无阻塞 >\_<#@! 18 | 19 | ## Live Example 20 | 21 | [MVVM - 功能演示](https://shalldie.github.io/demos/mini-mvvm/) 22 | 23 | ## Development && Production 24 | 25 | npm run dev:mini-mvvm 开发调试 26 | 27 | npm run build 生产构建 28 | 29 | ## Ability 30 | 31 | - [x] VNode 基于虚拟 dom: [virtual dom - mini-vdom](https://github.com/shalldie/mini-mvvm/tree/master/packages/mini-vdom) 32 | - [x] 数据监听 33 | - [x] `data`、`computed` 变动监听 34 | - [x] 数组方法监听 `push` | `pop` | `shift` | `unshift` | `splice` | `sort` | `reverse` 35 | - [x] `computed` 计算属性 36 | - [x] `文本节点` 数据绑定,可以是一段表达式 37 | - [x] `attribute` 数据绑定 38 | - [x] 支持绑定 data、computed,支持方法,可以是一段表达式 39 | - [x] 常用指令 40 | - [x] `m-model` 双向绑定。 支持 `input`、`textarea`、`select` 41 | - [x] `m-if` 条件渲染。条件支持 `data`、`computed`、一段表达式 42 | - [x] `m-for` 循环。`(item,index) in array`、`item in array` 43 | - [x] 事件绑定 44 | - [x] `@click` | `@mousedown` | `...` 。可以使用 `$event` 占位原生事件 45 | - [x] `watch` 数据监听,详见下方示例 46 | - [x] 声明方式 47 | - [x] api 方式 48 | - [x] 生命周期 49 | - [x] `created` 组件创建成功,可以使用 `this` 得到 MVVM 的实例 50 | - [x] `beforeMount` 将要被插入 dom 51 | - [x] `mounted` 组件被添加到 dom,可以使用 `this.$el` 获取根节点 dom 52 | - [x] `beforeUpdate` 组件将要更新 53 | - [x] `updated` 组件更新完毕 54 | 55 | ## Example 56 | 57 | ```ts 58 | import MVVM from 'mini-mvvm'; // es module, typescript 59 | // const MVVM from 'mini-mvvm'; // commonjs 60 | // const MVVM = window['MiniMvvm']; // window 61 | 62 | new MVVM({ 63 | // 挂载的目标节点的选择器 64 | // 如果没有 template,就用这个节点作为编译模板 65 | el: '#app', 66 | template: ` 67 |
姓名:{{ person.name }},年龄:{{ person.age }},性别:{{ person.sex }}
45 |{{ computedDescription }}
53 |79 | {{ item }} 80 | | 81 |
watch了list,任何操作都会保存在localstorage
88 |