├── .codeclimate.yml ├── .coveralls.yml ├── .eslintrc ├── .gitignore ├── .travis.yml ├── LICENSE.txt ├── README.md ├── avalon.cookbook.mobi ├── avalon1与avalon2的异同.md ├── build.js ├── buildIE6.js ├── buildIE6Sauce.js ├── buildIE6Test.js ├── buildIE9.js ├── buildIE9Test.js ├── buildTap.js ├── components ├── button │ └── index.js ├── grid.html ├── list │ └── index.html ├── loading │ └── 外面包一个专门loading的组件.html ├── logo.png ├── pager │ ├── component形式.html │ └── 非component形式.html ├── panel │ ├── index.js │ └── template.html ├── router │ ├── README.md │ ├── first.html │ ├── firstVm.js │ ├── heredoc.js │ ├── index.html │ ├── main.js │ ├── mmRouter.js │ ├── pagination.js │ ├── second.html │ ├── secondVm.js │ └── third.html └── select │ └── index.html ├── dist ├── arthur.js ├── avalon.js └── avalon.modern.js ├── index2.html ├── issue_template.md ├── karma.conf.js ├── karma.sauce.js ├── package.json ├── perf ├── ENV.js ├── _index.js ├── app.js ├── archur.html ├── component │ ├── onViewChange的触发.html │ ├── router │ │ ├── grid.template.html │ │ ├── ms-grid.css │ │ ├── ms-grid.js │ │ ├── tab1.html │ │ ├── tab1.js │ │ ├── tab2.html │ │ └── tab3.html │ ├── simplegrid.html │ ├── soleSlot的使用.html │ ├── 不带ms-的自定义标签.html │ ├── 与duplex联动.html │ ├── 使用slot做切换卡.html │ ├── 单个按钮.html │ ├── 多个slot.html │ ├── 弹出层(组件套组件).html │ ├── 循环生成必须加id.html │ ├── 按钮组件的不同声明方式.html │ ├── 树(组件形式).html │ ├── 树.html │ ├── 树2.html │ ├── 生命周期.html │ ├── 组件容器与组件模板的属性的优先级.html │ ├── 组件的VM.html │ └── 路由组件.html ├── controller │ ├── controller.html │ └── important.html ├── duplex │ ├── duplex.html │ ├── duplex2.html │ └── duplex3.html ├── effect │ ├── stagger.html │ └── 动画系统.html ├── event │ ├── on.html │ ├── on2.html │ └── swipe.html ├── for │ └── index.html ├── index-ko.html ├── index-ng.html ├── index-react.html ├── index-vue.html ├── index.html ├── index1.4.html ├── memory-stats.js ├── mithril.js ├── monitor.js ├── repaint.html ├── repeat │ ├── for.html │ ├── for2.html │ ├── for3.html │ ├── for4.html │ ├── for5.html │ ├── for_duplex.html │ └── 商品促销截止期变化例子.html ├── style.css ├── widget │ ├── index0.html │ ├── index1.html │ ├── index10.html │ ├── index11.html │ ├── index12.html │ ├── index13.html │ ├── index2.html │ ├── index3.html │ ├── index4.html │ ├── index5.html │ ├── index6.html │ ├── index7.html │ ├── index8.html │ └── index9.html └── 重点问题.html ├── router.build.js ├── src ├── REAMD.md ├── avalon.js ├── avalon.modern.js ├── avalon.tap.js ├── component │ └── index.js ├── directives │ ├── attr.compact.js │ ├── attr.modern.js │ ├── class.hover.active.js │ ├── compact.js │ ├── controller.js │ ├── css.js │ ├── duplex │ │ ├── compact.js │ │ ├── modern.js │ │ ├── option.js │ │ ├── share.js │ │ ├── updateDataActions.js │ │ ├── updateDataEvents.compact.js │ │ ├── updateDataEvents.modern.js │ │ └── updateDataHandle.js │ ├── expr.js │ ├── for.js │ ├── html.js │ ├── if.js │ ├── important.js │ ├── modern.js │ ├── on.js │ ├── rules.js │ ├── skip.js │ ├── text.js │ ├── validate.js │ └── visible.js ├── dom │ ├── attr │ │ ├── compact.js │ │ ├── isVML.js │ │ ├── modern.js │ │ ├── parseJSON.compact.js │ │ └── propMap.js │ ├── class │ │ ├── compact.js │ │ └── modern.js │ ├── compact.js │ ├── css │ │ ├── compact.js │ │ ├── modern.js │ │ └── share.js │ ├── event │ │ ├── canBubbleUp.js │ │ ├── compact.js │ │ ├── modern.js │ │ └── share.js │ ├── html │ │ └── index.js │ ├── modern.js │ ├── rcheckedType.js │ ├── ready │ │ ├── compact.js │ │ └── modern.js │ ├── shim │ │ ├── compact.js │ │ ├── fixClone.js │ │ ├── fixContains.js │ │ └── modern.js │ └── val │ │ ├── compact.js │ │ ├── getDuplexType.js │ │ ├── modern.js │ │ └── option.compact.js ├── effect │ ├── detect.js │ └── index.js ├── filters │ ├── array.js │ ├── date.js │ ├── escape.js │ ├── event.js │ ├── index.js │ ├── number.js │ └── sanitize.js ├── gesture │ ├── drag.js │ ├── pinch.js │ ├── press.js │ ├── readme.md │ ├── recognizer.js │ ├── rotate.js │ ├── swipe.js │ └── tap.js ├── pager.js ├── parser │ ├── attributes.js │ ├── index.js │ └── interpolate.js ├── renders │ ├── Directive.js │ ├── domRender.js │ ├── serverRender.js │ └── share.js ├── routergrid.js ├── seed │ ├── browser.js │ ├── cache.js │ ├── core.js │ ├── directive.js │ ├── lang.compact.js │ ├── lang.fix.js │ └── lang.modern.js ├── vdom │ ├── VComment.js │ ├── VElement.js │ ├── VElement.modern.js │ ├── VFragment.js │ ├── VText.js │ ├── compact.js │ └── modern.js ├── vmodel │ ├── Action.js │ ├── Computed.js │ ├── Mutation.js │ ├── ProxyArray.js │ ├── compact.js │ ├── modern.js │ ├── proxy.js │ ├── reserved.js │ ├── share.js │ └── transaction.js └── vtree │ ├── clearString.js │ ├── fromDOM.js │ ├── fromString.js │ ├── makeOrphan.js │ ├── makeTbody.js │ ├── orphanTag.js │ ├── validateDOMNesting.js │ └── voidTag.js ├── structure.jpg ├── test ├── beforeIt.js ├── directives │ ├── active.spec.js │ ├── attr.spec.js │ ├── class.spec.js │ ├── controller.spec.js │ ├── css.spec.js │ ├── duplex.spec.js │ ├── effect.spec.js │ ├── expr.spec.js │ ├── for.spec.js │ ├── hover.spec.js │ ├── if.spec.js │ ├── important.spec.js │ ├── on.spec.js │ ├── rules.spec.js │ ├── text.spec.js │ ├── validate.spec.js │ ├── visible.spec.js │ └── widget.spec.js ├── dom │ ├── attr.compact.spec.js │ ├── attr.modern.spec.js │ ├── class.compact.spec.js │ ├── class.modern.spec.js │ ├── css.compact.spec.js │ ├── css.modern.spec.js │ ├── event.compact.spec.js │ ├── event.modern.spec.js │ ├── html.spec.js │ ├── ready.compact.spec.js │ ├── ready.modern.spec.js │ ├── shim.compact.spec.js │ ├── shim.modern.spec.js │ ├── val.compact.spec.js │ └── val.modern.spec.js ├── filters │ └── index.spec.js ├── jquery.js ├── matchers.js ├── parser │ └── index.js ├── promise.js ├── seed │ ├── browser.spec.js │ ├── cache.spec.js │ ├── core.spec.js │ ├── lang.compact.spec.js │ └── lang.modern.spec.js ├── spec.js ├── spec.modern.js ├── test.js ├── vdom │ ├── compact.spec.js │ └── modern.spec.js ├── vmodel │ ├── compact.spec.js │ └── modern.spec.js └── vtree │ ├── clearString.spec.js │ ├── fromDOM.spec.js │ └── fromString.spec.js ├── tutorials ├── index.md ├── lesson01.md ├── lesson01_0.gif ├── lesson01_1.png ├── lesson02.md ├── lesson02.png ├── lesson03.html ├── lesson03.md ├── lesson03.png ├── lesson04.md ├── lesson04_0.gif ├── lesson04_1.gif ├── lesson04_2.gif ├── lesson05.md ├── lesson06.md ├── lesson06_0.gif ├── lesson06_1.gif ├── lesson06_2.gif ├── lesson07.md ├── lesson07_1.gif ├── lesson07_2.gif ├── lesson07_3.gif ├── lesson07_4.gif ├── lesson08.md ├── lesson08_1.gif ├── lesson08_2.gif ├── lesson09.md ├── lesson09_1.gif ├── lesson09_2.png ├── lesson09_3.gif ├── lesson09_4.gif ├── lesson10.md ├── lesson12.md └── lesson15.md ├── 手机上特殊处理.md └── 谁在用avalon.png /.codeclimate.yml: -------------------------------------------------------------------------------- 1 | --- 2 | engines: 3 | csslint: 4 | enabled: false 5 | duplication: 6 | enabled: false 7 | config: 8 | languages: 9 | - javascript 10 | eslint: 11 | enabled: true 12 | fixme: 13 | enabled: true 14 | ratings: 15 | paths: 16 | - "src/**.js" 17 | exclude_paths: 18 | - node_modules/**/* 19 | - test/**/* 20 | - tutorials/**/* 21 | - components/**/* 22 | - perf/**/* 23 | - dist/**/* -------------------------------------------------------------------------------- /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: travis-ci 2 | repo_token: 7PbHs1UhR24n9sP01rhKsHLXHaU4rUCvU 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | !/karma/repeat.js 2 | /nbproject/private/ -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 6 4 | branches: 5 | only: 6 | - master 7 | cache: 8 | directories: 9 | - node_modules 10 | before_script: 11 | - export CHROME_BIN=chromium-browser 12 | - export DISPLAY=:99.0 13 | - sh -e /etc/init.d/xvfb start 14 | install: 15 | - npm install 16 | - npm run buildAvalon 17 | script: 18 | - npm run build 19 | 20 | addons: 21 | code_climate: 22 | repo_token: cecb8ec105dc8e4b3f298312502f078a646f46ff 23 | after_success: 24 | - bash <(curl -s https://codecov.io/bash) 25 | - codeclimate-test-reporter < lcov.info 26 | env: 27 | global: 28 | - CODECOV_TOKEN: 31e8c855-5499-473e-b2b6-ba1d142fbb9e 29 | - secure: oteqj2CHMOma5RCv4YM/QPhqMfEzDtoibgsCT+ABjTUoj36T7HDxQfgiUspv0Iv33i7TmqHBHAPFVSsF+vz00NOTejMaaFfELUuRn4BTZ5zDuz6e6VXy0jgF/7is7dVAf6cqVaQ0Fo+X+XCLg63/CaX23S3IlqS1jyfuX+fpNh8QfaIOIXlaZ8yy6pyfqb+lMfOj4TTwpyFIoyono0qSGLdaSG9BDdZK0skBPeBP3sFiwtptMmY8Mhn7lLiulU0NHl0WSfJMH9FMe9mHdhqsSrFwACKT58JbXCkKdTLjszpMv1gkl+gynzyLOV3f1WqBv/calW65PBWu7uNKNgBILGW5L3THL4Qs6unvzVngeFcZ6jf9B4dtxpS22K3Pq7SkhJOgXNiEa6RavFQm6OFSjBjILiQvMSkWA2PcAxbqDr9oEbe/snUoeK+BbYli2kV3b5TR+wyKBgn6Wms8+QbTr2N8OnAMwhgmPS4if7uqyKNPCfMy4J2HZ3OEbAPTUUYtSSWaEhXAtV5aAXI0/LWTsXsVtvnxcHGdPtN6GKJyKDqAxKWECdCU9Je6fxGcXaEzU3VTlm9HmXuC3UpTERU7Pq9vrpqxYaWtt/M1r0WAeBrPPdZ+XOpL1Qn4fWV9B259+jKI8GNg5+07H54crDBXaV04kLZODPmTe+n8Sq7PsS8= 30 | - secure: QpQKoIDD6GlDglfXBxzuAxM/qLhEAyNO2TwzzeEG7PstLaYo94K+j4gbkiFkwbb2Oj5R/0Jtro1tSXM733DLieVZNyV7VrMkcwkkisR1KfWBynfToDHCkHqM6Rca3PiiVRFHqAh6KmkGZ7EAXXdPbjF49ZqOQMjikD5WKoMkAqagH4dREArBw+Al2qCn41JuLm+uKCJ8YpZysULTSxRoyFqvvXgxDUn6/NjM08Mo5BVmKvANKLO73qjW8y6MeXoAMuQ11YWKz6Wu++GCQvkg9/qy6P6RcOYY5C2+zjmscyI+lZZ9XWEfPNLTUhMxHX+M3LV4dlGcs46q2TX5XItnUKlRqZ2FtjI33nF+kNDD+ts7oD+H/HvsvkZC3wg4KU15XtTe2OP2oxQgOtW2S3j66IHeiWMI+5fj/nVKtmQx9Or41dDCSQQ2+7ieZA+gF4cfVkDMVJcF2joB5Wbzl4E/UoCN7lo1uLdMSPZqW6ePUtBoGlc70/oUj0w6Ct1wqYhIBwX/2P7QLjNLuwW6e0SPOsQDaa3Svqog3/mZL6lae7ARrCjLYh31E6I0mDcz2ea5Y5bzXmgXfViGaGbrN6nlWP+hpHsPvdW+yVyxfHCXDFuHJdGMxErEnIAlEA2dqPtGz8GwV03L0a7z7Vv4bomFnxf5HAtuUwQ1tJToANEGexk= 31 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright RubyLouvre(司徒正美) and other contributors 2 | 3 | http://avalonjs.github.io/ 4 | 5 | The following license applies to all parts of this software except as 6 | documented below: 7 | 8 | ==== 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining 11 | a copy of this software and associated documentation files (the 12 | "Software"), to deal in the Software without restriction, including 13 | without limitation the rights to use, copy, modify, merge, publish, 14 | distribute, sublicense, and/or sell copies of the Software, and to 15 | permit persons to whom the Software is furnished to do so, subject to 16 | the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be 19 | included in all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 25 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 26 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 27 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | 29 | ==== 30 | 31 | All files located in the node_modules and external directories are 32 | externally maintained libraries used by this software which have their 33 | own licenses; we recommend you read them, as their terms may differ from 34 | the terms above. -------------------------------------------------------------------------------- /avalon.cookbook.mobi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RubyLouvre/avalon/e405ca6e70d622a5c771079b4294a12fddfc1ca5/avalon.cookbook.mobi -------------------------------------------------------------------------------- /avalon1与avalon2的异同.md: -------------------------------------------------------------------------------- 1 | avalon1与avalon2的异同 2 | ================ 3 | 4 | | 科题 | avalon1 | avalon2 | 5 | | :-------------: |:-----------------| :-----| 6 | | 如何得知某个属性被改动 | 使用VBScript,Object.defineProperty实现对=号的重写 | 在此基础增加Proxy的魔术监听 | 7 | | 如何更新视图 | 找到变动属性对应的订阅者数组,执行这些数组元素的update方法 | 使用vm.$render生成虚拟DOM树,diff,从上到下有序更新 | 8 | | 计算属性 | 支持 | 移除 | 9 | | 绑定属性的处理 | 扫描后删除 | 扫描后还留着| 10 | | 循环指令 | ms-repeat,ms-each,ms-with | ms-for | 11 | | 循环指令的语法 | ms-repeat-el='array' | ms-for="el in @array" | 12 | | 如何辩别指令中的vm属性 | avalon自行进行语法抽取 | 强制在前面带@或##符号 | 13 | | 垃圾回收 | 密封舱机制,负责清空订阅者数组 | 由于不保存绑定对象,没有CG的烦恼 | 14 | | 性能 | 一般,但能撑起上万个指令,瓶颈取决于绑定对象的所占内存| 原来的5倍以上,瓶颈取决于虚拟DOM的规模| 15 | | 最复杂的指令 | ms-repeat| ms-duplex | 16 | | 组件指令 | ms-widget='id,name,opts' | ms-widget='Array'传入一个对象数组,用法更灵活 | 17 | | 组件生命周期 | onInit, onDispose | onInit, onReady, onViewChange, onDispose| 18 | | 动画 |ms-effect |ms-effect(与angular的animate更接近)| 19 | | 如何操作组件 | 通过onInit取得组件vm进行操作 | 直接操作配置对象| 20 | | 如何对组件传入大片内容 | 使用ms-html或改成模板 | 通过slot机制| 21 | | 加载器 | 使用AMD风格的内置加载器 | 移除,使用webpack进行打包| 22 | | 模块化 | 源码里自由划分 | 使用nodejs的require与module.exports组织起来| 23 | | important指令 | 有 |有(让页面渲染更快)| 24 | | {{}}|不完全等价于ms-text | 完全等价ms-text | 25 | | if指令 | ms-if="Boolean" | ms-if="Boolean" | 26 | | attr指令 | ms-attr-name=value | ms-attr="object" object是一个对象,方便每次处理多个属性 | 27 | | class指令 | ms-class='xxx: toggle' | ms-class=’Array|String‘ 用法变了| 28 | | visible指令 | ms-visible="Boolean" | ms-visible="Boolean" | 29 | | 过滤器 | 只能用于innerText中的{{}}及ms-text, ms-html | 数量琳琅满目,所有指令都支持| 30 | | 模板指令 | ms-include | 移除,由于后端无法实现等价功能 | 31 | | 事件指令 | 普通的事件绑定 | 能支持事件代理的都用事件代理 | 32 | | 数据验证 | 使用oniui的validation |使用内置的ms-validate,ms-duplex,ms-rules| 33 | | 后端渲染 | 实现成本高昂 | 支持 | 34 | | 核心架构 | 观察者模式 + 属性劫持 | 大模板函数+虚拟DOM+属性劫持| -------------------------------------------------------------------------------- /build.js: -------------------------------------------------------------------------------- 1 | var array = [ 2 | require('./buildIE6'), 3 | require('./buildIE6Test'), 4 | // require('./buildIE6Sauce'), 5 | 6 | require('./buildIE9'), 7 | require('./buildIE9Test') 8 | ] 9 | Promise.all(array).then(function() { 10 | console.log('build complete!!!') 11 | }).catch(function() { 12 | console.log('build error!!!') 13 | }) -------------------------------------------------------------------------------- /buildIE6Sauce.js: -------------------------------------------------------------------------------- 1 | var rollup = require('rollup'); 2 | var fs = require('fs'); 3 | var less = require('semicolon-less') 4 | 5 | //var babel = require('rollup-plugin-babel'); 6 | var babel = require("babel-core"); 7 | 8 | var transform = require('es3ify').transform; 9 | 10 | // used to track the cache for subsequent bundles 11 | var cache; 12 | 13 | module.exports = rollup.rollup({ 14 | 15 | entry: 'test/spec.js', 16 | 17 | cache: cache, 18 | 19 | plugins: [ 20 | 21 | ] 22 | }).then(function(bundle) { 23 | // Generate bundle + sourcemap 24 | var result = bundle.generate({ 25 | format: 'umd', 26 | moduleName: 'avalon' 27 | }); 28 | // Cache our bundle for later use (optional) 29 | cache = bundle; 30 | result.code = result.code.replace( 31 | /Object\.defineProperty\(exports,\s*'__esModule',\s*\{\s*value:\s*true\s*\}\);/, 32 | "exports.__esModule = true"). 33 | // replace(/'use strict';?/, ''). 34 | replace(/avalon\$1/g, 'avalon') 35 | 36 | result = babel.transform(result.code, { 37 | presets: ['avalon'], 38 | compact: false 39 | }) 40 | 41 | var code = transform(result.code).replace(/\}\)\(undefined,/, '})(this,') 42 | fs.writeFileSync('./dist/avalon.sauce.js', less(code)); 43 | 44 | }).catch(function(e) { 45 | console.log('error', e) 46 | }) -------------------------------------------------------------------------------- /buildIE6Test.js: -------------------------------------------------------------------------------- 1 | var rollup = require('rollup'); 2 | var fs = require('fs'); 3 | var less = require('semicolon-less') 4 | 5 | var istanbul = require('rollup-plugin-istanbul'); 6 | //var babel = require('rollup-plugin-babel'); 7 | var babel = require("babel-core"); 8 | 9 | var transform = require('es3ify').transform; 10 | 11 | // used to track the cache for subsequent bundles 12 | var cache; 13 | 14 | module.exports = rollup.rollup({ 15 | 16 | entry: 'test/spec.js', 17 | 18 | cache: cache, 19 | 20 | plugins: [ 21 | istanbul({ 22 | exclude: ['test/**/*.js'] 23 | }) 24 | ] 25 | }).then(function(bundle) { 26 | // Generate bundle + sourcemap 27 | var result = bundle.generate({ 28 | format: 'umd', 29 | moduleName: 'avalon' 30 | }); 31 | // Cache our bundle for later use (optional) 32 | cache = bundle; 33 | result.code = result.code.replace( 34 | /Object\.defineProperty\(exports,\s*'__esModule',\s*\{\s*value:\s*true\s*\}\);/, 35 | "exports.__esModule = true"). 36 | // replace(/'use strict';?/, ''). 37 | replace(/avalon\$1/g, 'avalon') 38 | 39 | result = babel.transform(result.code, { 40 | presets: ['avalon'], 41 | compact: false 42 | }) 43 | 44 | var code = transform(result.code).replace(/\}\)\(undefined,/, '})(this,') 45 | fs.writeFileSync('./dist/avalon.test.js', less(code)); 46 | 47 | }).catch(function(e) { 48 | console.log('error', e) 49 | }) -------------------------------------------------------------------------------- /buildIE9Test.js: -------------------------------------------------------------------------------- 1 | var rollup = require('rollup'); 2 | var fs = require('fs'); 3 | var istanbul = require('rollup-plugin-istanbul'); 4 | var babel = require("babel-core"); 5 | var less = require('semicolon-less') 6 | 7 | // used to track the cache for subsequent bundles 8 | var cache; 9 | 10 | module.exports = rollup.rollup({ 11 | // The bundle's starting point. This file will be 12 | // included, along with the minimum necessary code 13 | // from its dependencies 14 | entry: 'test/spec.modern.js', 15 | // If you have a bundle you want to re-use (e.g., when using a watcher to rebuild as files change), 16 | // you can tell rollup use a previous bundle as its starting point. 17 | // This is entirely optional! 18 | cache: cache, 19 | 20 | plugins: [ 21 | // istanbul({ 22 | // exclude: ['test/**/*.js'] 23 | // }) 24 | ] 25 | }).then(function(bundle) { 26 | // Generate bundle + sourcemap 27 | var result = bundle.generate({ 28 | format: 'umd', 29 | moduleName: 'avalon' 30 | }); 31 | // Cache our bundle for later use (optional) 32 | cache = bundle; 33 | var code = result.code.replace( 34 | /Object\.defineProperty\(exports,\s*'__esModule',\s*\{\s*value:\s*true\s*\}\);/, 35 | "exports.__esModule = true"). 36 | // replace(/'use strict';?/,'') 37 | replace(/avalon\$1/g, 'avalon') 38 | 39 | result = babel.transform(code, { 40 | presets: ['avalon'], 41 | compact: false 42 | }) 43 | 44 | code = result.code.replace(/\}\)\(undefined,/, '})(this,') 45 | fs.writeFileSync('./dist/avalon.modern.test.js', less(code)); 46 | 47 | }).catch(function(e) { 48 | console.log('error', e) 49 | }) -------------------------------------------------------------------------------- /components/button/index.js: -------------------------------------------------------------------------------- 1 | //var avalon = require('avalon') 2 | 3 | avalon.component('ms-button', { 4 | template: '', 5 | defaults: { 6 | buttonText: "button" 7 | }, 8 | soleSlot: 'buttonText' 9 | }) -------------------------------------------------------------------------------- /components/grid.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |这里可以是复杂的HTML
'], 11 | formatCard: function(e) { 12 | var el = e.target 13 | var caret = el.selectionStart 14 | var value = el.value 15 | var prev = value.slice(0, caret) 16 | var sp = (prev.match(/\s/) || []).length 17 | var curr = value.replace(/\s/g, '').replace(/(\d{4})/g, "$1 ").trim() 18 | var now = curr.slice(0, caret) 19 | var curSp = (now.match(/\s/) || []).length 20 | el.value = curr 21 | //同步到ms-duplex中的pos去 22 | el._ms_duplex_.pos = caret + curSp - sp 23 | } 24 | 25 | }) 26 | //成绩单 27 | //大家可以对比一下1.*的相同实现 28 | //http://www.cnblogs.com/rubylouvre/p/3213430.html 29 | var model = avalon.define({ 30 | $id: 'transcript', 31 | id: '', 32 | name: '', 33 | score: 0, 34 | total: 0, 35 | array: [], 36 | add: function() { 37 | this.array.push({ 38 | id: this.id, 39 | name: this.name, 40 | score: this.score 41 | }) 42 | } 43 | }) 44 | 45 | model.$watch("score", function(a) { 46 | var a = Number(a) || 0 47 | a = a > 100 ? 100 : a < 0 ? 0 : a //强制转换为0~100间 48 | model.score = a 49 | }) 50 | model.$watch("array", function() { 51 | var a = 0 52 | model.array.forEach(function(el) { 53 | a += el.score //求得总数 54 | }) 55 | model.total = a; 56 | model.id = "" 57 | model.name = "" 58 | model.score = 0 59 | }) 60 | model.array = [ 61 | { id: "d1", name: "李世民", score: 67 }, 62 | { id: "d2", name: "赢政", score: 90 } 63 | ] 64 | module.exports = vm -------------------------------------------------------------------------------- /components/router/heredoc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * 注意不要压缩这个模块 3 | */ 4 | module.exports = function heredoc(fn) { 5 | return fn.toString().replace(/^[^\/]+\/\*!?\s?/, ''). 6 | replace(/\*\/[^\/]+$/, '').trim().replace(/>\s*<') 7 | } 8 | -------------------------------------------------------------------------------- /components/router/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |{{@currPath}}
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /components/router/main.js: -------------------------------------------------------------------------------- 1 | var avalon = require('../../dist/avalon') 2 | var mmRouter = require('./mmRouter') 3 | var html1 = require('./first.html') 4 | var html2 = require('./second.html') 5 | var html3 = require('./third.html') 6 | var vm1 = require('./firstVm') 7 | var vm2 = require('./secondVm') 8 | 9 | var root = avalon.define({ 10 | $id: 'main', 11 | currPath: 'aaa',//只是用于测试 12 | currPage: 'aaa' //这是有用的 13 | }) 14 | 15 | 16 | var states = {} 17 | 18 | function addState(path, vm, html) { 19 | states[path] = { 20 | vm: vm, 21 | html: html 22 | } 23 | } 24 | 25 | addState('aaa', vm1, html1) 26 | 27 | addState('bbb', vm2, html2) 28 | 29 | addState('ccc', avalon.define({ 30 | $id: 'third', 31 | aaa: 333 32 | }), html3) 33 | 34 | 35 | avalon.component('ms-view', { 36 | template: '', 37 | defaults: { 38 | page: ' ', 39 | path: 'no', 40 | 41 | onReady: function(e) { 42 | var path = e.vmodel.path 43 | var state = states[path] 44 | avalon.vmodels[state.vm.$id] = state.vm 45 | setTimeout(function() {//必须等它扫描完这个template,才能替换 46 | e.vmodel.page = state.html 47 | },100) 48 | 49 | }, 50 | onDispose: function(e) { 51 | var path = e.vmodel.path 52 | var state = states[path] 53 | var vm = state.vm 54 | var render = vm.render 55 | render && render.dispose() 56 | delete avalon.vmodels[vm.$id] 57 | } 58 | } 59 | }) 60 | 61 | function getPage(path) { 62 | path = path.slice(1) 63 | var html = '| 64 | {{el}} 65 | | 66 |
| {{el}} | 71 |
| 全选 | 52 |
| 55 | {{$index}}::{{el.checked}} 56 | 57 | 58 | | 59 | 60 |