Skip to content

Commit 6e778a3

Browse files
committed
feature: client: sort: migrate to ESM
1 parent e27ef51 commit 6e778a3

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

client/cloudcmd.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const wraptile = require('wraptile');
77
const load = require('load.js');
88

99
const {registerSW, listenSW} = require('./sw/register');
10+
const {initSortPanel, sortPanel} = require('./sort.mjs');
1011

1112
const isDev = process.env.NODE_ENV === 'development';
1213

@@ -21,11 +22,12 @@ module.exports = async (config) => {
2122

2223
require('./listeners');
2324
require('./key');
24-
require('./sort');
2525

26+
initSortPanel();
27+
globalThis.CloudCmd.sortPanel = sortPanel;
2628
const prefix = getPrefix(config.prefix);
2729

28-
window.CloudCmd.init(prefix, config);
30+
globalThis.CloudCmd.init(prefix, config);
2931

3032
if (window.CloudCmd.config('menu') === 'aleman')
3133
setTimeout(() => {

client/sort.mjs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
1-
'use strict';
2-
31
/* global CloudCmd */
4-
const DOM = require('./dom');
2+
import {fullstore} from 'fullstore';
3+
import DOM from './dom/index.js';
54

6-
const Info = DOM.CurrentInfo;
7-
const {sort, order} = CloudCmd;
8-
const position = DOM.getPanelPosition();
9-
let sortPrevious = sort[position];
5+
const sortPrevious = fullstore();
106

117
const {getPanel} = DOM;
128

13-
CloudCmd.sortPanel = (name, panel = getPanel()) => {
9+
export const initSortPanel = () => {
10+
const {sort, order} = CloudCmd;
11+
const position = DOM.getPanelPosition();
12+
13+
sortPrevious(sort[position]);
14+
};
15+
16+
export const sortPanel = (name, panel = getPanel()) => {
17+
const {sort, order} = CloudCmd;
18+
const Info = DOM.CurrentInfo;
1419
const position = panel.dataset.name.replace('js-', '');
1520

16-
if (name !== sortPrevious)
21+
if (name !== sortPrevious())
1722
order[position] = 'asc';
1823
else if (order[position] === 'asc')
1924
order[position] = 'desc';
2025
else
2126
order[position] = 'asc';
2227

23-
sortPrevious = name;
28+
sortPrevious(name);
2429
sort[position] = name;
2530
const noCurrent = position !== Info.panelPosition;
2631

@@ -29,3 +34,4 @@ CloudCmd.sortPanel = (name, panel = getPanel()) => {
2934
noCurrent,
3035
});
3136
};
37+

0 commit comments

Comments
 (0)