Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
fix automerge call-sties
Browse files Browse the repository at this point in the history
  • Loading branch information
philcockfield committed Oct 19, 2023
1 parent 3ef71db commit 813ccc3
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 39 deletions.
2 changes: 2 additions & 0 deletions code/ext/ext.lib.automerge/src/ui/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ export type {
CssEdgesInput,
CssValue,
DevCtxState,
GetLabelItem,
LabelItem,
LabelItemRendererArgs,
LabelItemRenderers,
LabelItemState,
LabelListDispatch,
LabelListState,
PropListProps,
RenderCountProps,
Expand Down
14 changes: 9 additions & 5 deletions code/ext/ext.lib.automerge/src/ui/ui.RepoList/-SPEC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ export default Dev.describe(name, (e) => {
.size([330, null])
.display('grid')
.render<T>((e) => {
const current = model.list.current;
const renderCount: t.RenderCountProps = {
absolute: [-20, 2, null, null],
opacity: 0.2,
prefix: 'list.render-',
};
return (
<List
list={current.state}
items={current.items}
<RepoList
//
list={model.list}
renderers={model.renderers}
renderCount={{ absolute: [-20, 2, null, null], opacity: 0.2, prefix: 'list.render-' }}
renderCount={renderCount}
/>
);
});
Expand Down
9 changes: 6 additions & 3 deletions code/ext/ext.lib.automerge/src/ui/ui.RepoList/Model.Item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const ItemModel = {
/**
* Behavior.
*/
const add = () => {
const add = async () => {
const ctx = args.ctx();
console.log('add', store);
state.change((d) => {
Expand All @@ -49,9 +49,12 @@ export const ItemModel = {
dispatch.redraw();

ctx.list.change((d) => {
const next = ItemModel.state(args);
d.items.push(next);
// const items = d.items || (d.items = []);
// const next = ItemModel.state(args);
// items.push(next);
});

ctx.dispatch.redraw();
};

const mode = () => Data.item(state).mode;
Expand Down
30 changes: 23 additions & 7 deletions code/ext/ext.lib.automerge/src/ui/ui.RepoList/Model.List.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
import { PatchState, Model, type t } from './common';
import { ItemModel } from './Model.Item';
import { renderers } from './Model.Item.render';

export const List = {
/**
* Initialise a new state model for a Repo.
*/
init(store: t.Store) {
const ctx: t.GetRepoListCtx = () => ({ list });
const ctx: t.GetRepoListCtx = () => ({ list, dispatch });
const first = ItemModel.init({ store, ctx });
const renderers = first.renderers;
const initial: t.RepoList = {
state: Model.List.state(),
items: [first.state],

const getItem: t.GetLabelItem = (target) => {
if (typeof target === 'number') {
const index = target;
if (index === 0) return [first.state, index];
} else {
/**
* TODO 🐷
*/
}

return [undefined, -1];
};
const list = PatchState.init<t.RepoList>({ initial });
return { list, renderers };

const list = Model.List.state({ total: 1, getItem });
const dispatch = Model.List.commands(list);

return {
ctx,
list,
renderers: renderers({ ctx }),
} as const;
},
} as const;
8 changes: 5 additions & 3 deletions code/ext/ext.lib.automerge/src/ui/ui.RepoList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import { type t } from './common';
* <Component>
*/
export type RepoListProps = {
list?: t.RepoListState;
renderers?: t.RepoItemRenderers;
renderCount?: t.RenderCountProps;
style?: t.CssValue;
};

/**
* Model: Context
*/
export type GetRepoListCtx = () => RepoListCtx;
export type RepoListCtx = { list: RepoListState };
export type RepoListCtx = { list: RepoListState; dispatch: t.LabelListDispatch };

/**
* Model: Item
Expand All @@ -24,8 +27,7 @@ export type RepoItemRenderers = t.LabelItemRenderers<t.RepoListAction>;
/**
* Model: List
*/
export type RepoListState = t.PatchState<t.RepoList>;
export type RepoList = { state: t.LabelListState; items: t.RepoItemState[] };
export type RepoListState = t.LabelListState;

/**
* Model: Data
Expand Down
24 changes: 12 additions & 12 deletions code/ext/ext.lib.automerge/src/ui/ui.RepoList/ui.List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@ import { LabelItem, RenderCount, css, type t } from './common';

export type ListProps = {
list?: t.LabelListState;
items?: t.RepoItemState[];
renderers?: t.RepoItemRenderers;
style?: t.CssValue;
renderCount?: t.RenderCountProps;
};

export const List: React.FC<ListProps> = (props) => {
const { list, items = [] } = props;
const controller = LabelItem.Stateful.useListController({ list, items });
const { list } = props;
const { ref, Provider } = LabelItem.Stateful.useListController({ list });

/**
* [Render]
*/
const styles = {
base: css({ position: 'relative', outline: 'none' }),
base: css({ position: 'relative' }),
};

const elements = items.map((item, i) => {
const elements = LabelItem.Model.List.map(list, (item, i) => {
return (
<LabelItem.Stateful
key={`item.${i}`}
key={item.instance}
index={i}
total={length}
list={controller.list}
list={list}
item={item}
renderers={props.renderers}
/>
);
});

return (
<div ref={controller.ref} {...css(styles.base, props.style)} tabIndex={0}>
{props.renderCount && <RenderCount {...props.renderCount} />}
<div>{elements}</div>
</div>
<Provider>
<div ref={ref} {...css(styles.base, props.style)}>
{props.renderCount && <RenderCount {...props.renderCount} />}
<div>{elements}</div>
</div>
</Provider>
);
};
21 changes: 12 additions & 9 deletions code/ext/ext.lib.automerge/src/ui/ui.RepoList/ui.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { useEffect, useRef, useState } from 'react';
import { Color, COLORS, css, DEFAULTS, FC, rx, type t } from './common';
import { css, type t } from './common';
import { List } from './ui.List';

export const View: React.FC<t.RepoListProps> = (props) => {
const { list, renderers } = props;

/**
* [Render]
* Render
*/
const styles = {
base: css({
backgroundColor: 'rgba(255, 0, 0, 0.1)' /* RED */,
}),
base: css({ position: 'relative' }),
};

return (
<div {...css(styles.base, props.style)}>
<div>{`🐷 Store List`}</div>
</div>
<List
//
list={list}
renderers={renderers}
renderCount={props.renderCount}
/>
);
};
3 changes: 3 additions & 0 deletions code/ext/ext.lib.peerjs/src/ui/ui.Connector/Model.List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export const List = {
if (index === 0) return [self, index];
if (index === 1) return [first, index];
} else {
/**
* TODO 🐷
*/
}

return [undefined, -1];
Expand Down

0 comments on commit 813ccc3

Please sign in to comment.