mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-11-01 19:32:27 +08:00
chore (frontend): move url in frontend
This commit is contained in:
49
public/assets/lib/rx.js
Normal file
49
public/assets/lib/rx.js
Normal file
@ -0,0 +1,49 @@
|
||||
import { onDestroy } from "./skeleton/index.js";
|
||||
import * as rxjs from "./vendor/rxjs.min.js";
|
||||
|
||||
// https://github.com/ReactiveX/rxjs/issues/4416#issuecomment-620847759
|
||||
import * as ajaxModule from "./vendor/rxjs-ajax.min.js";
|
||||
|
||||
export default rxjs;
|
||||
export const ajax = ajaxModule.ajax;
|
||||
|
||||
export function effect(obs) {
|
||||
const tmp = obs.subscribe(() => {}, (err) => { throw err; });
|
||||
onDestroy(() => tmp.unsubscribe());
|
||||
}
|
||||
|
||||
const getFn = (obj, arg0, ...args) => {
|
||||
if (arg0 === undefined) return obj;
|
||||
const next = obj[arg0];
|
||||
return getFn(next.bind ? next.bind(obj) : next, ...args);
|
||||
};
|
||||
|
||||
export function applyMutation($node, ...keys) {
|
||||
if (!$node) throw new Error("undefined node");
|
||||
const execute = getFn($node, ...keys);
|
||||
return rxjs.tap((val) => Array.isArray(val) ? execute(...val) : execute(val));
|
||||
}
|
||||
|
||||
export function applyMutations($node, ...keys) {
|
||||
if (!$node) throw new Error("undefined node");
|
||||
const execute = getFn($node, ...keys);
|
||||
return rxjs.tap((vals) => vals.forEach((val) => {
|
||||
execute(val);
|
||||
}));
|
||||
}
|
||||
|
||||
export function stateMutation($node, attr) {
|
||||
if (!$node) throw new Error("undefined node");
|
||||
return rxjs.tap((val) => $node[attr] = val);
|
||||
}
|
||||
|
||||
export function preventDefault() {
|
||||
return rxjs.tap((e) => e.preventDefault());
|
||||
}
|
||||
|
||||
export function onClick($node) {
|
||||
if (!$node) return rxjs.EMPTY;
|
||||
return rxjs.fromEvent($node, "click").pipe(
|
||||
rxjs.map(() => $node),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user