Skip to content

Commit

Permalink
Merge pull request #12171 from richard-cox/reactivity
Browse files Browse the repository at this point in the history
Update model reactivety
  • Loading branch information
richard-cox authored Oct 18, 2024
2 parents 83a9402 + 12fa019 commit 24f3a76
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions shell/plugins/dashboard-store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,24 @@ function registerType(state, type) {
}

export function replace(existing, data) {
const existingPropertyMap = {};

for ( const k of Object.keys(existing) ) {
delete existing[k];
existingPropertyMap[k] = true;
}

let newProperty = false;

for ( const k of Object.keys(data) ) {
if (!newProperty && !existingPropertyMap[k]) {
newProperty = true;
}

existing[k] = data[k];
}

return existing;
return newProperty ? reactive(existing) : existing;
}

function replaceResource(existing, data, getters) {
Expand Down Expand Up @@ -125,7 +134,7 @@ export function load(state, {
entry = replaceResource(entry, data, getters);
} else {
// There's no entry, make a new proxy
entry = classify(ctx, data);
entry = reactive(classify(ctx, data));
}
}

Expand Down Expand Up @@ -268,7 +277,7 @@ export function batchChanges(state, { ctx, batch }) {
if (normalizedType === SCHEMA) {
addSchemaIndexFields(resource);
}
const classyResource = classify(ctx, resource);
const classyResource = reactive(classify(ctx, resource));

if (index === undefined) {
typeCache.list.push(classyResource);
Expand Down Expand Up @@ -396,6 +405,9 @@ export default {
}
},

/**
* Load the results of a request that used a selector (like label)
*/
loadSelector(state, {
type, entries, ctx, selector, revision
}) {
Expand All @@ -412,6 +424,9 @@ export default {
cache.revision = revision || 0;
},

/**
* Load the results of a request to fetch all resources or all resources in a namespace
*/
loadAll,

/**
Expand Down Expand Up @@ -441,8 +456,14 @@ export default {
});
},

/**
* Load resources, but don't set `haveAll`
*/
loadAdd,

/**
* Load the results of a request for a page. Often used to exercise advanced filtering
*/
loadPage(state, {
type,
data,
Expand Down

0 comments on commit 24f3a76

Please sign in to comment.