diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/blacklists.js | 13 | ||||
-rw-r--r-- | src/shared/store/index.js | 53 | ||||
-rw-r--r-- | src/shared/store/provider.jsx | 15 |
3 files changed, 13 insertions, 68 deletions
diff --git a/src/shared/blacklists.js b/src/shared/blacklists.js new file mode 100644 index 0000000..19ed3f1 --- /dev/null +++ b/src/shared/blacklists.js @@ -0,0 +1,13 @@ +import * as re from 'shared/utils/re'; + +const includes = (blacklist, url) => { + let u = new URL(url); + return blacklist.some((item) => { + if (!item.includes('/')) { + return re.fromWildcard(item).test(u.hostname); + } + return re.fromWildcard(item).test(u.hostname + u.pathname); + }); +}; + +export { includes }; diff --git a/src/shared/store/index.js b/src/shared/store/index.js deleted file mode 100644 index 2fafdf1..0000000 --- a/src/shared/store/index.js +++ /dev/null @@ -1,53 +0,0 @@ -class Store { - constructor(reducer, catcher) { - this.reducer = reducer; - this.catcher = catcher; - this.subscribers = []; - try { - this.state = this.reducer(undefined, {}); - } catch (e) { - catcher(e); - } - } - - dispatch(action, sender) { - if (action instanceof Promise) { - action.then((a) => { - this.transitNext(a, sender); - }).catch((e) => { - this.catcher(e, sender); - }); - } else { - try { - this.transitNext(action, sender); - } catch (e) { - this.catcher(e, sender); - } - } - return action; - } - - getState() { - return this.state; - } - - subscribe(callback) { - this.subscribers.push(callback); - } - - transitNext(action, sender) { - let newState = this.reducer(this.state, action); - if (JSON.stringify(this.state) !== JSON.stringify(newState)) { - this.state = newState; - this.subscribers.forEach(f => f(sender)); - } - } -} - -const empty = () => {}; - -const createStore = (reducer, catcher = empty) => { - return new Store(reducer, catcher); -}; - -export { createStore }; diff --git a/src/shared/store/provider.jsx b/src/shared/store/provider.jsx deleted file mode 100644 index fe925aa..0000000 --- a/src/shared/store/provider.jsx +++ /dev/null @@ -1,15 +0,0 @@ -import { h, Component } from 'preact'; - -class Provider extends Component { - getChildContext() { - return { store: this.props.store }; - } - - render() { - return <div> - { this.props.children } - </div>; - } -} - -export default Provider; |