@cicada/render
Advanced tools
Comparing version 1.1.16-alpha to 1.1.16-alpha2
@@ -12,6 +12,10 @@ 'use strict'; | ||
expect(statePath('repeat.items.0').relativeBind().toString()).toEqual('repeat.items.0'); | ||
expect(statePath('repeat.items.0.INNER-xxx-xxx.Col(_2)').relativeBind().toString()).toEqual('repeat.items.0'); | ||
}); | ||
it('statePath.index', function () { | ||
expect(statePath('repeat.items.0.Col(_2).abc').index()).toEqual(0); | ||
expect(statePath('repeat.items.0').index()).toEqual(0); | ||
expect(statePath('repeat.items.9.Col(_2).1.abc.2').index()).toEqual(2); | ||
expect(statePath('repeat.items.9.Col(_2).1.abc.2').index(1)).toEqual(1); | ||
expect(statePath('repeat.items.9.Col(_2).1.abc.2').index(2)).toEqual(9); | ||
expect(statePath('repeat.items.9.Col(_2).1.abc.2').index(3)).toEqual(9); | ||
expect(statePath('repeat.items.9').index()).toEqual(9); | ||
}); |
@@ -57,5 +57,12 @@ 'use strict'; | ||
function remove(inputStatePath) { | ||
var result = _exist2.default.remove(store, inputStatePath); | ||
listeners.notify(inputStatePath); | ||
return result; | ||
} | ||
return { | ||
set: set, | ||
get: get, | ||
remove: remove, | ||
merge: (0, _util.partialRight)(set, true), | ||
@@ -62,0 +69,0 @@ collect: collector.collect, |
@@ -128,5 +128,7 @@ 'use strict'; | ||
var arr = this.toString().split('.'); | ||
// 这里用括号判断是不是引擎生成的bind | ||
while (arr[arr.length - 1] !== undefined && /[()]/.test(arr[arr.length - 1])) { | ||
var lastBind = arr[arr.length - 1]; | ||
// 这里用括号判断是不是引擎生成的bind, 用INNER判断是不是自动化测试生成的bind | ||
while (lastBind !== undefined && (/[()]/.test(lastBind) || /^INNER/.test(lastBind))) { | ||
arr.pop(); | ||
lastBind = arr[arr.length - 1]; | ||
} | ||
@@ -140,9 +142,20 @@ return new StatePath(arr.join('.')); | ||
value: function index() { | ||
var arr = this.toString().split('.'); | ||
var i = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
var arr = this.toString().split('.').filter(function (k) { | ||
return !(/[()]/.test(k) || /^INNER/.test(k)); | ||
}); | ||
var lastBind = arr[arr.length - 1]; | ||
var lastIndex = 0; | ||
// 这里寻找最接近的索引 | ||
while (arr[arr.length - 1] !== undefined) { | ||
if (/^[0-9]+$/.test(arr[arr.length - 1])) return Number(arr[arr.length - 1]); | ||
while (lastBind !== undefined) { | ||
if (/^[0-9]+$/.test(lastBind)) { | ||
if (i <= 0) return Number(lastBind); | ||
lastIndex = Number(lastBind); | ||
i--; | ||
} | ||
arr.pop(); | ||
lastBind = arr[arr.length - 1]; | ||
} | ||
return 0; | ||
return lastIndex; | ||
} | ||
@@ -149,0 +162,0 @@ }, { |
{ | ||
"name": "@cicada/render", | ||
"version": "1.1.16-alpha", | ||
"version": "1.1.16-alpha2", | ||
"main": "./lib/index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
397156
9658
70