Skip to content

Commit

Permalink
Merge pull request #13266 from nextcloud/chore/shallow-reactive-array…
Browse files Browse the repository at this point in the history
…-warn
  • Loading branch information
Antreesy authored Sep 11, 2024
2 parents a2e4713 + b991291 commit 229f3b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/services/SettingsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { readonly, shallowReactive } from 'vue'
import { readonly, ref, markRaw } from 'vue'
import type { Ref } from 'vue'

import { emit } from '@nextcloud/event-bus'

Expand All @@ -22,24 +23,25 @@ type TalkSettingsSection = {
element: string
}

const customSettingsSections: TalkSettingsSection[] = shallowReactive([])
// TODO: use shallowReactive instead of ref + markRaw in Vue 3 (see file commit history)
const customSettingsSections: Ref<TalkSettingsSection[]> = ref([])

/**
* Register a custom settings section
* @param section - Settings section
*/
function registerSection(section: TalkSettingsSection) {
customSettingsSections.push(section)
customSettingsSections.value.push(markRaw(section))
}

/**
* Unregister a custom settings section
* @param id - Section ID
*/
function unregisterSection(id: string) {
const index = customSettingsSections.findIndex((section) => section.id === id)
const index = customSettingsSections.value.findIndex((section) => section.id === id)
if (index !== -1) {
customSettingsSections.splice(index, 1)
customSettingsSections.value.splice(index, 1)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/services/__tests__/SettingsAPI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('SettingsAPI', () => {

it('should have registerSection method to register settings sections', () => {
const { customSettingsSections } = useCustomSettings()
expect(customSettingsSections).toEqual([])
expect(customSettingsSections.value).toEqual([])
expect(SettingsAPI.registerSection).toBeDefined()
SettingsAPI.registerSection({
id: 'test',
Expand All @@ -32,7 +32,7 @@ describe('SettingsAPI', () => {
name: 'Test 2',
element: 'test-element-two',
})
expect(customSettingsSections).toEqual([{
expect(customSettingsSections.value).toEqual([{
id: 'test',
name: 'Test',
element: 'test-element',
Expand All @@ -45,7 +45,7 @@ describe('SettingsAPI', () => {

it('should have unregisterSection method to unregister settings sections', () => {
const { customSettingsSections } = useCustomSettings()
expect(customSettingsSections).toEqual([{
expect(customSettingsSections.value).toEqual([{
id: 'test',
name: 'Test',
element: 'test-element',
Expand All @@ -56,7 +56,7 @@ describe('SettingsAPI', () => {
}])
expect(SettingsAPI.unregisterSection).toBeDefined()
SettingsAPI.unregisterSection('test')
expect(customSettingsSections).toEqual([{
expect(customSettingsSections.value).toEqual([{
id: 'test2',
name: 'Test 2',
element: 'test-element-two',
Expand Down

0 comments on commit 229f3b0

Please sign in to comment.