This repository has been archived on 2023-08-29. You can view files and clone it, but cannot push or open issues/pull-requests.
yutent
/
anot.js
Archived
1
0
Fork 0

Compare commits

..

No commits in common. "master" and "2.2.2" have entirely different histories.

5 changed files with 65 additions and 50 deletions

View File

@ -1,18 +1,19 @@
/**
*
* @authors yutent (yutent.io@gmail.com)
* @authors yutent (yutent@doui.cc)
* @date 2018-08-04 01:00:06
*/
'use strict'
require('es.shim')
const fs = require('iofs')
const path = require('path')
const chokidar = require('chokidar')
const { minify } = require('terser')
const uglify = require('uglify-es')
const chalk = require('chalk')
const config = require('./package.json')
const log = console.log
const VERSION = config.version
const VERSION = '2.0.0'
const PACK_DIR = path.resolve('./dist')
const SOURCE_DIR = path.resolve('./src/')
@ -58,9 +59,9 @@ export default _Anot
function comment({ touch } = {}) {
return `/*==================================================
* Anot ${touch ? 'touch' : 'normal'} version for future browsers
* @authors yutent<yutent.io@gmail.com>
* @date ${new Date().format()}
* @version v${VERSION}
* @authors yutent (yutent@doui.cc)
* @date 2017-03-21 21:05:57
* V${VERSION}
*
==================================================*/
`
@ -114,8 +115,8 @@ function packNoCompress(file) {
* 打包带触摸事件的未来版的 anot
* --------------------------------------------------------
*/
fs.echo(Buffer.concat([PAD_START, touchVer, PAD_END]), './dist/anot.touch.js')
log('%s 打包完成...', chalk.green('anot.touch.js'))
fs.echo(Buffer.concat([PAD_START, touchVer, PAD_END]), './dist/anot-touch.js')
log('%s 打包完成...', chalk.green('anot-touch.js'))
}
// 打包并压缩
@ -135,24 +136,22 @@ function packAndCompress() {
*/
log('正在打包 anot.js...')
let normalVerPack = Buffer.concat([PAD_START, normalVer, PAD_END]).toString()
minify(normalVerPack, { sourceMap: false }).then(res => {
fs.echo(comment() + res.code, './dist/anot.js')
log(chalk.green('anot.js 打包压缩完成!'))
})
fs.echo(comment() + uglify.minify(normalVerPack).code, './dist/anot.js')
log(chalk.green('anot.js 打包压缩完成!'))
/**
* --------------------------------------------------------
* 打包带触摸事件的未来版的 anot
* --------------------------------------------------------
*/
log('正在打包 anot.touch.js...')
log('正在打包 anot-touch.js...')
let touchVerPack = Buffer.concat([PAD_START, touchVer, PAD_END]).toString()
minify(touchVerPack, { sourceMap: false }).then(res => {
fs.echo(comment({ touch: true }) + res.code, './dist/anot.touch.js')
log(chalk.green('anot.touch.js 打包压缩完成!'))
})
fs.echo(
comment({ touch: true }) + uglify.minify(touchVerPack).code,
'./dist/anot-touch.js'
)
log(chalk.green('anot-touch.js 打包压缩完成!'))
}
let args = process.argv.slice(2)

View File

@ -1,6 +1,6 @@
{
"name": "anot",
"version": "2.2.4",
"version": "2.2.2",
"description": "Anot - 迷你mvvm框架",
"main": "dist/anot.js",
"files": ["dist"],
@ -14,9 +14,9 @@
"devDependencies": {
"chalk": "^2.4.1",
"chokidar": "^2.0.4",
"es.shim": "^2.0.1",
"iofs": "^1.5.2",
"terser": "^5.0.0"
"es.shim": "^1.1.2",
"iofs": "^1.1.0",
"uglify-es": "^3.3.9"
},
"repository": "https://github.com/yutent/anot.js.git",
"author": "yutent",

View File

@ -16,7 +16,7 @@ npm run prod
```
执行完, 会打包为2个版本, 分别是
- anot.js 普通版(需要支持es6 module的现代浏览器)
- anot.touch.js 带触摸事件的版本(需要支持es6 module的现代浏览器)
- anot-touch.js 带触摸的版本(需要支持es6 module的现代浏览器)
### 文档:

View File

@ -4,7 +4,14 @@ let Anot = function(el) {
}
/*视浏览器情况采用最快的异步回调*/
Anot.nextTick = (function() {
Anot.nextTick = new (function() {
// jshint ignore:line
let tickImmediate = window.setImmediate
let tickObserver = window.MutationObserver
if (tickImmediate) {
return tickImmediate.bind(window)
}
let queue = []
function callback() {
let n = queue.length
@ -14,16 +21,21 @@ Anot.nextTick = (function() {
queue = queue.slice(n)
}
let node = document.createTextNode('<!-- -->')
new MutationObserver(callback).observe(node, { characterData: true })
let bool = false
return function(fn) {
queue.push(fn)
bool = !bool
node.data = bool
if (tickObserver) {
let node = document.createTextNode('anot')
new tickObserver(callback).observe(node, { characterData: true }) // jshint ignore:line
let bool = false
return function(fn) {
queue.push(fn)
bool = !bool
node.data = bool
}
}
})()
return function(fn) {
setTimeout(fn, 4)
}
})() // jshint ignore:line
/*********************************************************************
* Anot的静态方法定义区 *
@ -85,7 +97,10 @@ Anot.PropsTypes.isBoolean = function() {
/*判定是否是一个朴素的javascript对象Object不是DOM对象不是BOM对象不是自定义类的实例*/
Anot.isPlainObject = function(obj) {
// 简单的 typeof obj === "object"检测会致使用isPlainObject(window)在opera下通不过
return serialize.call(obj) === '[object Object]' && Object.getPrototypeOf(obj) === oproto
return (
serialize.call(obj) === '[object Object]' &&
Object.getPrototypeOf(obj) === oproto
)
}
let VMODELS = (Anot.vmodels = {}) //所有vmodel都储存在这里
@ -165,7 +180,11 @@ Anot.mix = Anot.fn.mix = function() {
if (target === copy) {
continue
}
if (deep && copy && (Anot.isPlainObject(copy) || (copyIsArray = Array.isArray(copy)))) {
if (
deep &&
copy &&
(Anot.isPlainObject(copy) || (copyIsArray = Array.isArray(copy)))
) {
if (copyIsArray) {
copyIsArray = false
clone = src && Array.isArray(src) ? src : []
@ -271,11 +290,11 @@ Anot.mix({
t = t.trim()
let hook = hooks[t]
if (typeof hook === 'object') {
t = hook.type || t
phase = hook.phase || phase
t = hook.type || type
phase = hook.phase || !!phase
fn = hook.fix ? hook.fix(el, fn) : fn
}
el.addEventListener(t, fn, !!phase)
el.addEventListener(t, fn, phase)
})
return fn
},
@ -288,10 +307,10 @@ Anot.mix({
t = t.trim()
let hook = hooks[t]
if (typeof hook === 'object') {
t = hook.type || t
phase = hook.phase || phase
t = hook.type || type
phase = hook.phase || !!phase
}
el.removeEventListener(t, fn, !!phase)
el.removeEventListener(t, fn, phase)
})
},
/*读写删除元素节点的样式*/
@ -459,9 +478,10 @@ Anot.mix({
},
//获取url的参数
search: function(key) {
key += ''
let uri = location.search
if (!uri) {
if (!key || !uri) {
return null
}
uri = decode(uri)
@ -485,11 +505,7 @@ Anot.mix({
obj[tmp[0]] = tmp[1]
}
}
if (key) {
return obj.hasOwnProperty(key) ? obj[key] : null
} else {
return obj
}
return obj.hasOwnProperty(key) ? obj[key] : null
},
//复制文本到粘贴板
copy: function(txt) {

View File

@ -264,8 +264,8 @@ function observeObject(source, options) {
return (old = value.get.call(this))
},
set: function(x) {
var older = old
var newer
var older = old,
newer
value.set.call(this, x)
newer = this[key]
if (this.$fire && newer !== older) {