mirror of
https://github.com/liriliri/eruda.git
synced 2026-03-24 09:48:37 +08:00
Add info get api #83
This commit is contained in:
@@ -159,6 +159,21 @@ info.add('title', 'content');
|
||||
info.add('location', () => location.href);
|
||||
```
|
||||
|
||||
### get
|
||||
|
||||
Get info or infos.
|
||||
|
||||
|Name |Type |Desc |
|
||||
|------|---------------|------------|
|
||||
|name |string |Info name |
|
||||
|return|string function|Info content|
|
||||
|
||||
```javascript
|
||||
info.add('title', 'content')
|
||||
info.get(); // -> [{name: 'title', val: 'content'}]
|
||||
info.get('title') // -> 'content'
|
||||
```
|
||||
|
||||
### remove
|
||||
|
||||
Remove specified info.
|
||||
|
||||
1122
doc/UTIL_API.md
1122
doc/UTIL_API.md
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
import Tool from '../DevTools/Tool'
|
||||
import defInfo from './defInfo'
|
||||
import { evalCss, each, isFn } from '../lib/util'
|
||||
import { evalCss, each, isFn, isUndef, cloneDeep } from '../lib/util'
|
||||
|
||||
export default class Info extends Tool {
|
||||
constructor() {
|
||||
@@ -28,8 +28,8 @@ export default class Info extends Tool {
|
||||
evalCss.remove(this._style)
|
||||
}
|
||||
add(name, val) {
|
||||
let infos = this._infos,
|
||||
isUpdate = false
|
||||
let infos = this._infos
|
||||
let isUpdate = false
|
||||
|
||||
each(infos, info => {
|
||||
if (name !== info.name) return
|
||||
@@ -44,6 +44,21 @@ export default class Info extends Tool {
|
||||
|
||||
return this
|
||||
}
|
||||
get(name) {
|
||||
let infos = this._infos
|
||||
|
||||
if (isUndef(name)) {
|
||||
return cloneDeep(infos)
|
||||
}
|
||||
|
||||
let result
|
||||
|
||||
each(infos, info => {
|
||||
if (name === info.name) result = info.val
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
remove(name) {
|
||||
let infos = this._infos
|
||||
|
||||
|
||||
1663
src/lib/util.js
1663
src/lib/util.js
File diff suppressed because it is too large
Load Diff
@@ -39,6 +39,12 @@ describe('info', function() {
|
||||
expect($tool.find('.eruda-content')).toContainText('eruda')
|
||||
})
|
||||
|
||||
it('get', function() {
|
||||
expect(tool.get()).toEqual([{ name: 'test', val: 'eruda' }])
|
||||
expect(tool.get('test')).toBe('eruda')
|
||||
expect(tool.get('test2')).not.toBeDefined()
|
||||
})
|
||||
|
||||
it('remove', function() {
|
||||
tool.remove('test')
|
||||
expect($tool.find('li')).toHaveLength(0)
|
||||
|
||||
Reference in New Issue
Block a user