Skip to content

Commit

Permalink
perf: ♻️ Improve code robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Jul 13, 2024
1 parent 3d4dc7c commit 2f389af
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
:is="item.component"
v-if="isRender(item)"
:ref="item.prop"
:re-render="reRender"
/>
</el-tab-pane>
</el-tabs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<script>
import ApplicationProxy from '$/components/Device/components/ControlBar/Application/index.vue'
import { allSettled } from '$/utils'
import { allSettledWrapper } from '$/utils'
export default {
components: {
Expand Down Expand Up @@ -50,7 +50,7 @@ export default {
this.loading = true
await allSettled(this.devices, (item) => {
await allSettledWrapper(this.devices, (item) => {
return this.$refs.applicationProxyRef.invoke(item, { files })
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ElMessage } from 'element-plus'
import FileManageProxy from '$/components/Device/components/ControlBar/FileManage/index.vue'
import { selectAndSendFileToDevice } from '$/utils/device/index.js'
import { allSettled } from '$/utils'
import { allSettledWrapper } from '$/utils'
const props = defineProps({
devices: {
Expand Down Expand Up @@ -58,7 +58,7 @@ async function handlePush(devices) {
loading.value = true
await allSettled(devices, (item) => {
await allSettledWrapper(devices, (item) => {
return fileManageProxyRef.value.handlePush(item, { files })
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<script>
import ScreenshotProxy from '$/components/Device/components/ControlBar/Screenshot/index.vue'
import { allSettled, sleep } from '$/utils'
import { allSettledWrapper, sleep } from '$/utils'
export default {
components: {
Expand All @@ -28,7 +28,7 @@ export default {
async handleClick() {
this.loading = true
await allSettled(this.devices, (item) => {
await allSettledWrapper(this.devices, (item) => {
return this.$refs.screenshotProxyRef.invoke(item)
})
Expand Down
4 changes: 2 additions & 2 deletions src/components/Device/components/BatchActions/Shell/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script setup>
import { ElMessage, ElMessageBox } from 'element-plus'
import { selectAndSendFileToDevice } from '$/utils/device/index.js'
import { allSettled } from '$/utils'
import { allSettledWrapper } from '$/utils'
const props = defineProps({
devices: {
Expand Down Expand Up @@ -44,7 +44,7 @@ async function handleClick(devices) {
const failFiles = []
await allSettled(devices, async (device) => {
await allSettledWrapper(devices, async (device) => {
const successFiles = await selectAndSendFileToDevice(device.id, {
files,
loadingText: window.t('device.control.shell.push.loading'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</template>

<script>
import { allSettled } from '$/utils'
import { allSettledWrapper } from '$/utils'
export default {
props: {
Expand Down Expand Up @@ -55,7 +55,7 @@ export default {
let failCount = 0
await allSettled(files, (item) => {
await allSettledWrapper(files, (item) => {
return this.$adb.install(device.id, item).catch((e) => {
console.warn(e)
++failCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { ElMessage } from 'element-plus'
import { selectAndSendFileToDevice } from '$/utils/device/index.js'
import { useDeviceStore } from '$/store'
import { allSettled } from '$/utils'
import { allSettledWrapper } from '$/utils'
const props = defineProps({
device: {
Expand Down Expand Up @@ -65,7 +65,7 @@ async function handlePush(device, { files } = {}) {
let failCount = 0
await allSettled(files, (item) => {
await allSettledWrapper(files, (item) => {
return window.adbkit.push(device.id, item).catch(() => {
++failCount
})
Expand Down
5 changes: 0 additions & 5 deletions src/components/Preference/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ export default {
deviceScope,
}
},
computed: {
preferenceModel() {
return this.preferenceStore.model || {}
},
},
watch: {
'preferenceData': {
handler() {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/device/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ElMessage } from 'element-plus'
import { allSettled } from '$/utils'
import { allSettledWrapper } from '$/utils'
/**
* 选择并将文件发送到设备
*/
Expand Down Expand Up @@ -42,7 +42,7 @@ export async function selectAndSendFileToDevice(
const successFiles = []
const failFiles = []

await allSettled(files, async (item) => {
await allSettledWrapper(files, async (item) => {
const ret = await window.adbkit.push(deviceId, item).catch((e) => {
console.warn(e?.message)
failFiles.push(`${deviceId}-${item}`)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ export function keyByValue(data, key = 'key', valueKey = 'value') {
* throw new Error('奇数');
* }
* };
* allSettled(list, iterator).then(console.log);
* allSettledWrapper(list, iterator).then(console.log);
*/
export function allSettled(list = [], iterator) {
export function allSettledWrapper(list = [], iterator) {
const promises = []

for (let index = 0; index < list.length; index++) {
Expand Down

0 comments on commit 2f389af

Please sign in to comment.