Skip to content

Commit

Permalink
Modify mangle
Browse files Browse the repository at this point in the history
  • Loading branch information
aralroca committed Nov 23, 2021
1 parent b2dcb70 commit ae5ebf0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
21 changes: 21 additions & 0 deletions mangle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"minify": {
"mangle": {
"properties": {
"regex": "^_"
}
},
"compress": {
"hoist_vars": true,
"reduce_funcs": true
}
},
"props": {
"cname": 6,
"props": {
"$_subscribe": "s",
"$_notify": "n",
"$_unsubscribe": "u"
}
}
}
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,5 @@
"react-dom": "17.0.2",
"react-test-renderer": "17.0.2"
},
"mangle": {
"regex": "^_"
},
"bugs": "https://github.com/teafuljs/teaful/issues"
}
5 changes: 4 additions & 1 deletion package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default function createStore(defaultStore = {}, callback) {
}

let result = extras.reduce((res, fn) => {
let newRes = fn(res, subscription._subscribe);
let newRes = fn(res, subscription);
return typeof newRes === 'object' ? {...res, ...newRes} : res;
}, {useStore, getStore, withStore});

Expand All @@ -184,18 +184,21 @@ function createSubscription() {
let listeners = {};

return {
// Renamed to "s" after build to minify code
_subscribe(path, listener) {
if (typeof listener !== 'function') return;
if (!listeners[path]) listeners[path] = new Set();
listeners[path].add(listener);
},
// Renamed to "n" after build to minify code
_notify(path, params) {
Object.keys(listeners).forEach((listenerKey) => {
if (path.startsWith(listenerKey) || listenerKey.startsWith(path)) {
listeners[listenerKey].forEach((listener) => listener(params));
}
});
},
// Renamed to "u" after build to minify code
_unsubscribe(path, listener) {
if (typeof listener !== 'function') return;
listeners[path].delete(listener);
Expand Down
5 changes: 3 additions & 2 deletions tests/extras.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import createStore from '../package/index';
describe('Extras', () => {
it('should be possible to register a library extra',
async () => {
createStore.ext(({getStore}, subscribe) => {
createStore.ext(({getStore}, subscription) => {
const [, setTest2] = getStore.test2();
subscribe('.', ({store}) => {
// Renamed to "subscription.s()" after build to minify code
subscription._subscribe('.', ({store}) => {
if (store.test === 3 && !store.test2) {
setTest2(4);
}
Expand Down

0 comments on commit ae5ebf0

Please sign in to comment.