Skip to content

Commit

Permalink
refactor: use chobitsu
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Jul 3, 2020
1 parent 49db104 commit 78c2881
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 682 deletions.
3 changes: 2 additions & 1 deletion .eustia.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
module.exports = {
eruda: {
library: 'https://raw.githubusercontent.com/liriliri/fione/master/',
library: ['fione', 'node_modules/eustia-module'],
files: 'src/**/*.js',
ignore: 'src/**/stringify.js',
output: 'src/lib/util.js',
exclude: ['createCfg'],
format: 'es'
},
test: {
library: ['node_modules/eustia-module'],
files: ['test/*.js', 'test/*.html'],
exclude: ['js'],
namespace: 'util',
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ dist/
node_modules/
test/lib/
coverage/
eustia/
test/playground.html
npm-debug.log
package-lock.json
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "fione"]
path = fione
url = [email protected]:liriliri/fione.git
3 changes: 3 additions & 0 deletions build/webpack.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const cssMinifierLoader = {

module.exports = {
entry: './src/index',
resolve: {
symlinks: false
},
devServer: {
contentBase: './test',
port: 3000
Expand Down
131 changes: 8 additions & 123 deletions doc/UTIL_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,14 @@ Emit event.
|event |Event name |
|...args|Arguments passed to listener|

### removeAllListeners

Remove all listeners.

|Name |Desc |
|-----|----------|
|event|Event name|

### mixin

[static] Mixin object class methods.
Expand Down Expand Up @@ -964,46 +972,6 @@ contain({ a: 1, b: 2 }, 1); // -> true
contain('abc', 'a'); // -> true
```

## cookie

Simple api for handling browser cookies.

### get

Get cookie value.

|Name |Desc |
|------|--------------------------|
|key |Cookie key |
|return|Corresponding cookie value|

### set

Set cookie value.

|Name |Desc |
|-------|--------------|
|key |Cookie key |
|val |Cookie value |
|options|Cookie options|
|return |Module cookie |

### remove

Remove cookie value.

|Name |Desc |
|-------|--------------|
|key |Cookie key |
|options|Cookie options|
|return |Module cookie |

```javascript
cookie.set('a', '1', { path: '/' });
cookie.get('a'); // -> '1'
cookie.remove('a');
```

## copy

Copy text to clipboard using document.execCommand.
Expand Down Expand Up @@ -1106,20 +1074,6 @@ const calLayout = debounce(function() {}, 300);
// $(window).resize(calLayout);
```

## decodeUriComponent

Better decodeURIComponent that does not throw if input is invalid.

|Name |Desc |
|------|----------------|
|str |String to decode|
|return|Decoded string |

```javascript
decodeUriComponent('%%25%'); // -> '%%%'
decodeUriComponent('%E0%A4%A'); // -> '\xE0\xA4%A'
```

## defaults

Fill in undefined properties in object with the first value present in the following list of defaults objects.
Expand Down Expand Up @@ -2449,18 +2403,6 @@ Reverse array without mutating it.
reverse([1, 2, 3]); // -> [3, 2, 1]
```

## rmCookie

Loop through all possible path and domain to remove cookie.

|Name|Desc |
|----|----------|
|key |Cookie key|

```javascript
rmCookie('test');
```

## root

Root object reference, `global` in nodeJs, `window` in browser.
Expand Down Expand Up @@ -2768,35 +2710,6 @@ type(async function() {}, false); // -> 'AsyncFunction'

Used for typescript definitions only.

## ucs2

UCS-2 encoding and decoding.

### encode

Create a string using an array of code point values.

|Name |Desc |
|------|--------------------|
|arr |Array of code points|
|return|Encoded string |

### decode

Create an array of code point values using a string.

|Name |Desc |
|------|--------------------|
|str |Input string |
|return|Array of code points|

```javascript
ucs2.encode([0x61, 0x62, 0x63]); // -> 'abc'
ucs2.decode('abc'); // -> [0x61, 0x62, 0x63]
'𝌆'.length; // -> 2
ucs2.decode('𝌆').length; // -> 1
```

## uncaught

Handle global uncaught errors and promise rejections.
Expand Down Expand Up @@ -2872,34 +2785,6 @@ Convert the first character of string to upper case.
upperFirst('red'); // -> Red
```

## utf8

UTF-8 encoding and decoding.

### encode

Turn any UTF-8 decoded string into UTF-8 encoded string.

|Name |Desc |
|------|----------------|
|str |String to encode|
|return|Encoded string |

### decode

Turn any UTF-8 encoded string into UTF-8 decoded string.

|Name |Desc |
|----------|----------------------|
|str |String to decode |
|safe=false|Suppress error if true|
|return |Decoded string |

```javascript
utf8.encode('\uD800\uDC00'); // -> '\xF0\x90\x80\x80'
utf8.decode('\xF0\x90\x80\x80'); // -> '\uD800\uDC00'
```

## values

Create an array of the own enumerable property values of object.
Expand Down
1 change: 1 addition & 0 deletions fione
Submodule fione added at 94408e
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
"autoprefixer": "^9.7.4",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.0.6",
"chobitsu": "^0.2.0",
"css-loader": "^3.4.2",
"draggabilly": "^2.2.0",
"eslint": "^6.8.0",
"eslint-loader": "^3.0.3",
"eustia-module": "^1.23.0",
"handlebars": "^4.7.3",
"handlebars-loader": "^1.7.1",
"html-minifier": "^4.0.0",
Expand Down
31 changes: 12 additions & 19 deletions src/Resources/Resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import {
MutationObserver,
toArr,
concat,
rmCookie,
decodeUriComponent,
isNull,
lowerCase,
contain,
filter
filter,
map
} from '../lib/util'
import { isErudaEl } from '../lib/extraUtil'
import evalCss from '../lib/evalCss'
import chobitsu from 'chobitsu'

export default class Resources extends Tool {
constructor() {
Expand Down Expand Up @@ -155,20 +155,11 @@ export default class Resources extends Tool {
this['_' + type + 'StoreData'] = storeData
}
refreshCookie() {
const cookieData = []

const cookie = document.cookie
if (trim(cookie) !== '') {
each(document.cookie.split(';'), function(val) {
val = val.split('=')
const key = trim(val.shift())
val = decodeUriComponent(val.join('='))
cookieData.push({
key,
val
})
})
}
const { cookies } = chobitsu.domain('Network').getCookies()
const cookieData = map(cookies, ({ name, value }) => ({
key: name,
val: value
}))

this._cookieData = cookieData

Expand Down Expand Up @@ -283,7 +274,7 @@ export default class Resources extends Tool {
.on('click', '.eruda-delete-cookie', function() {
const key = $(this).data('key')

rmCookie(key)
chobitsu.domain('Network').deleteCookies({ name: key })
self.refreshCookie()._render()
})
.on('click', '.eruda-clear-storage', function() {
Expand All @@ -300,7 +291,9 @@ export default class Resources extends Tool {
}
})
.on('click', '.eruda-clear-cookie', () => {
each(this._cookieData, val => rmCookie(val.key))
chobitsu.domain('Storage').clearDataForOrigin({
storageTypes: 'cookies'
})
this.refreshCookie()._render()
})
.on('click', '.eruda-storage-val', function() {
Expand Down
2 changes: 2 additions & 0 deletions src/eruda.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
nextTick
} from './lib/util'
import evalCss from './lib/evalCss'
import chobitsu from 'chobitsu'

export default {
init({ container, tool, autoScale = true, useShadowDom = true, defaults = {} } = {}) {
Expand All @@ -47,6 +48,7 @@ export default {
_isInit: false,
version: VERSION,
util,
chobitsu,
Tool,
Console,
Elements,
Expand Down
Loading

0 comments on commit 78c2881

Please sign in to comment.