Skip to content

Commit

Permalink
items refactor wip
Browse files Browse the repository at this point in the history
  • Loading branch information
brollin committed May 16, 2024
1 parent 250a97e commit 5010886
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
22 changes: 6 additions & 16 deletions ui/learn/src/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,22 @@ export interface Items<T> {

export function ctrl(blueprint: { apples: string | Key[] }): Items<'apple'> {
const items: Partial<Record<Key, 'apple'>> = {};
util.readKeys(blueprint.apples).forEach(function (key: Key) {
util.readKeys(blueprint.apples).forEach((key: Key) => {
items[key] = 'apple';
});

const get = function (key: Key) {
return items[key];
};

const list = function () {
return Object.values(items);
};

return {
get: get,
withItem: function <U>(key: Key, f: (item: 'apple') => U) {
get: (key: Key) => items[key],
withItem: <U>(key: Key, f: (item: 'apple') => U) => {
const item = items[key];
if (item) return f(item);
return;
},
remove: function (key: Key) {
remove: (key: Key) => {
delete items[key];
},
hasItem: function (item: 'apple') {
return list().includes(item);
},
appleKeys: function () {
hasItem: (item: 'apple') => Object.values(items).includes(item),
appleKeys: () => {
const keys: Key[] = [];
for (const k in items) if (items[k as Key] === 'apple') keys.push(k as Key);
return keys;
Expand Down
4 changes: 1 addition & 3 deletions ui/learn/src/levelCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ export class LevelCtrl {
},
// TODO:
// items: {
// render: function (_pos: unknown, key: Key) {
// return items.withItem(key, itemView);
// },
// render: (_pos: unknown, key: Key) => items.withItem(key, itemView),
// },
premovable: { enabled: true },
drawable: { enabled: true, eraseOnClick: true },
Expand Down

0 comments on commit 5010886

Please sign in to comment.