Skip to content

Commit 28a3824

Browse files
committed
fix: correct context_items instantiation in get_context_items method
refactor: remove exclusion handling from load_from_data method
1 parent 2b39a57 commit 28a3824

2 files changed

Lines changed: 8 additions & 18 deletions

File tree

smart-contexts/context_items.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { ImageContextItemAdapter } from './adapters/context-items/image.js';
77
import { PdfContextItemAdapter } from './adapters/context-items/pdf.js';
88

99
export class ContextItems extends Collection {
10+
constructor(smart_context, opts = {}) {
11+
super(smart_context.env || smart_context, opts); // OR pass directly for env loading (temp patch, should now be loaded by env)
12+
this.smart_context = smart_context;
13+
}
1014
async load() {
1115
console.log('ContextItems: load called');
1216
// TODO DECIDED: add default settings from context_item_merge_template action if not already present????
@@ -51,28 +55,13 @@ export class ContextItems extends Collection {
5155
load_from_data(context_items_data, params = {}) {
5256
// delete this.items; // clear existing items (REMOVED TO ALLOW RECURSION FOR NAMED CONTEXTS)
5357
if(!this.items) this.items = {};
54-
const entries = Object.entries(context_items_data || {})
55-
// sort by exclude first (exclude === true)
56-
.sort(([, a_data], [, b_data]) => {
57-
const a_exclude = a_data.exclude === true ? 1 : 0;
58-
const b_exclude = b_data.exclude === true ? 1 : 0;
59-
return a_exclude - b_exclude; // ascending: non-exclude (0) before exclude (1)
60-
})
61-
;
58+
const entries = Object.entries(context_items_data || {});
6259
for (let i = 0; i < entries.length; i++) {
6360
const [key, item_data] = entries[i];
64-
if(item_data.exclude) {
65-
this.load_exclusion_from_data(key, item_data, params);
66-
}
6761
this.load_item_from_data(key, item_data, params);
6862
}
6963
}
7064

71-
load_exclusion_from_data(key, item_data, params = {}) {
72-
if(!this._exclude_patterns) this._exclude_patterns = [];
73-
this._exclude_patterns.push(key);
74-
}
75-
7665
load_item_from_data(key, item_data, params = {}) {
7766
if (item_data.named_context) {
7867
const named_context = this.env.smart_contexts.filter((ctx) => ctx.data.name === key)[0];
@@ -100,6 +89,7 @@ export class ContextItems extends Collection {
10089
});
10190
}
10291
}
92+
10393
}
10494

10595
export default {

smart-contexts/smart_context.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class SmartContext extends CollectionItem {
4444
data: {
4545
key: '',
4646
context_items: {},
47-
context_opts: {},
47+
context_opts: {}, // REMOVE?
4848
},
4949
};
5050
}
@@ -241,7 +241,7 @@ export class SmartContext extends CollectionItem {
241241
get_context_items(params = {}) {
242242
const config = this.env.config.collections.context_items;
243243
const Class = config.class;
244-
const context_items = new Class(this.env, { ...config, class: null });
244+
const context_items = new Class(this, { ...config, class: null });
245245
context_items.load_from_data(this.data.context_items || {}, params);
246246
return context_items;
247247
}

0 commit comments

Comments
 (0)