You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ac...@apache.org on 2017/11/23 13:31:50 UTC
incubator-weex git commit: - [jsfm] remove directive filter in
attributes
Repository: incubator-weex
Updated Branches:
refs/heads/master 0535ac604 -> 3c5b1241f
- [jsfm] remove directive filter in attributes
- [jsfm] remove test cases of directive filter
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/3c5b1241
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/3c5b1241
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/3c5b1241
Branch: refs/heads/master
Commit: 3c5b1241f4ee1fd6588a5914695fd96100b7865e
Parents: 0535ac6
Author: Hanks <zh...@gmail.com>
Authored: Wed Nov 22 19:06:02 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Thu Nov 23 21:27:52 2017 +0800
----------------------------------------------------------------------
html5/runtime/vdom/Element.js | 5 +-
html5/runtime/vdom/directive.js | 69 -----------------
html5/test/unit/runtime/vdom/directive.js | 101 -------------------------
3 files changed, 2 insertions(+), 173 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/3c5b1241/html5/runtime/vdom/Element.js
----------------------------------------------------------------------
diff --git a/html5/runtime/vdom/Element.js b/html5/runtime/vdom/Element.js
index 01e3045..712b925 100644
--- a/html5/runtime/vdom/Element.js
+++ b/html5/runtime/vdom/Element.js
@@ -30,7 +30,6 @@ import {
} from './operation'
import { uniqueId } from '../utils'
import { getWeexElement, setElement } from './WeexElement'
-import { filterDirective } from './directive'
const DEFAULT_TAG_NAME = 'div'
const BUBBLE_EVENTS = [
@@ -289,7 +288,7 @@ export default class Element extends Node {
const taskCenter = getTaskCenter(this.docId)
if (!silent && taskCenter) {
const result = {}
- result[key] = filterDirective(value)
+ result[key] = value
taskCenter.send(
'dom',
{ action: 'updateAttrs' },
@@ -471,7 +470,7 @@ export default class Element extends Node {
const result = {
ref: this.ref.toString(),
type: this.type,
- attr: filterDirective(this.attr),
+ attr: this.attr,
style: this.toStyle()
}
const event = []
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/3c5b1241/html5/runtime/vdom/directive.js
----------------------------------------------------------------------
diff --git a/html5/runtime/vdom/directive.js b/html5/runtime/vdom/directive.js
deleted file mode 100644
index 4d82fde..0000000
--- a/html5/runtime/vdom/directive.js
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { typof } from '../utils'
-
-// match the binding delimiter
-const delimiterRE = /\[\[((?:.|\n)+?)\]\]/g
-
-export function generateBinding (text) {
- if (typof(text) === 'String') {
- return { '@binding': text }
- }
- return text
-}
-
-export function parseString (string) {
- const tokens = []
- let lastIndex = delimiterRE.lastIndex = 0
- let match, index
- while ((match = delimiterRE.exec(string))) {
- index = match.index
- if (index > lastIndex) {
- tokens.push(string.slice(lastIndex, index))
- }
- const binding = generateBinding(match[1].trim())
- tokens.push(binding)
- lastIndex = index + match[0].length
- }
- if (lastIndex < string.length) {
- tokens.push(string.slice(lastIndex))
- }
- if (tokens.length === 1) {
- return tokens[0]
- }
- return tokens
-}
-
-export function filterDirective (value) {
- if (typof(value) === 'String' && delimiterRE.test(value)) {
- return parseString(value)
- }
- if (typof(value) === 'Object') {
- const realData = {}
- for (const key in value) {
- realData[key] = filterDirective(value[key])
- }
- return realData
- }
- if (typof(value) === 'Array') {
- return value.map(filterDirective)
- }
- return value
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/3c5b1241/html5/test/unit/runtime/vdom/directive.js
----------------------------------------------------------------------
diff --git a/html5/test/unit/runtime/vdom/directive.js b/html5/test/unit/runtime/vdom/directive.js
deleted file mode 100644
index cafb33d..0000000
--- a/html5/test/unit/runtime/vdom/directive.js
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { expect } from 'chai'
-import { filterDirective } from '../../../../runtime/vdom/directive'
-
-describe('filterDirective', () => {
- it('other type', () => {
- expect(filterDirective(0)).to.be.equal(0)
- expect(filterDirective(53)).to.be.equal(53)
- expect(filterDirective(null)).to.be.equal(null)
- const reg = /\w+/i
- expect(filterDirective(reg)).to.be.equal(reg)
- })
-
- it('normal string', () => {
- expect(filterDirective('')).to.be.equal('')
- expect(filterDirective('-1')).to.be.equal('-1')
- expect(filterDirective('abc')).to.be.equal('abc')
- expect(filterDirective(' a bc d')).to.be.equal(' a bc d')
- expect(filterDirective(' a {{ bc }}')).to.be.equal(' a {{ bc }}')
- })
-
- it('binding', () => {
- expect(filterDirective('[[abc]]')).to.deep.equal({ '@binding': 'abc' })
- expect(filterDirective('[[ xyz ]]')).to.deep.equal({ '@binding': 'xyz' })
- expect(filterDirective('[[ x y z ]]')).to.deep.equal({ '@binding': 'x y z' })
- })
-
- it('binding and normal string', () => {
- expect(filterDirective('xyz[[abc]]ttt')).to.deep.equal(['xyz', { '@binding': 'abc' }, 'ttt'])
- expect(filterDirective(' x [[ w ]] t ')).to.deep.equal([' x ', { '@binding': 'w' }, ' t '])
- expect(filterDirective('[[ wn]][xx{uur}]')).to.deep.equal([{ '@binding': 'wn' }, '[xx{uur}]'])
- })
-
- it('multi-binding', () => {
- expect(filterDirective('[[abc]][[wpc]]')).to.deep.equal([{ '@binding': 'abc' }, { '@binding': 'wpc' }])
- expect(filterDirective('abcd[[ xyz ]]ef[[w]]gh')).to.deep.equal([
- 'abcd',
- { '@binding': 'xyz' },
- 'ef',
- { '@binding': 'w' },
- 'gh'
- ])
- expect(filterDirective(' a [[ b ]] [[c]] d [[e]][[f]]g')).to.deep.equal([
- ' a ',
- { '@binding': 'b' },
- ' ',
- { '@binding': 'c' },
- ' d ',
- { '@binding': 'e' },
- { '@binding': 'f' },
- 'g'
- ])
- })
-
- it('parse object', () => {
- expect(filterDirective({ key: '[[x]]' })).to.deep.equal({ key: { '@binding': 'x' }})
- expect(filterDirective({ a: '[[A]]', b: '[[B]]' })).to.deep.equal({
- a: { '@binding': 'A' },
- b: { '@binding': 'B' }
- })
- expect(filterDirective({
- a: '[[A]]',
- x: 'X',
- y: {
- b: ' - [[B]] - ',
- z: {
- c: ['[[C]] + [[C]]', 'cc'],
- w: 24
- }
- }
- })).to.deep.equal({
- a: { '@binding': 'A' },
- x: 'X',
- y: {
- b: [' - ', { '@binding': 'B' }, ' - '],
- z: {
- c: [[{ '@binding': 'C' }, ' + ', { '@binding': 'C' }], 'cc'],
- w: 24
- }
- }
- })
- })
-})