Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(store): add block collection and selector #6737

Merged
merged 10 commits into from
Apr 12, 2024
Merged

Conversation

Saul-Mirone
Copy link
Collaborator

@Saul-Mirone Saul-Mirone commented Apr 11, 2024

Block Collection and Selector

Block collection is the abstract layer that holds the data source of a y.doc.
It is used to compute block models of a doc.
The compute process can be controlled by a selector.

This feature is designed to make it possible to partially render the data source.

Doc = BlockCollection(Selector)

If there's a doc contains following blocks:

<affine-page id="0">
  <affine-note id="1">
    <affine-paragraph id="2" />
    <affine-list id="3" />
  </affine-note>
</affine-page>

If we pass in a selector like this:

const selector = (block, doc) => {
  return block.model.flavour !== 'affine:list';
} 
const doc = collection.getDoc(docId, selector)

You'll get:

<affine-page id="0">
  <affine-note id="1">
    <affine-paragraph id="2" />
  </affine-note>
</affine-page>

With the same selector, you'll always get the same instance:

const selector = (block, doc) => {
  return block.model.flavour !== 'affine:list';
} 
const doc1 = collection.getDoc(docId, selector)
const doc2 = collection.getDoc(docId, selector)

doc1 === doc2 // true;

All getDoc and createDoc will have () => true as the default selector.

Copy link

vercel bot commented Apr 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
blocksuite ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 12, 2024 7:49am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
blocksuite-docs ⬜️ Ignored (Inspect) Visit Preview Apr 12, 2024 7:49am

@Saul-Mirone Saul-Mirone changed the title feat(store): add doc collection feat(store): add doc collection and selector Apr 12, 2024
@Saul-Mirone Saul-Mirone merged commit ea96eb9 into master Apr 12, 2024
20 checks passed
@Saul-Mirone Saul-Mirone deleted the doc-collection branch April 12, 2024 07:53
@Saul-Mirone Saul-Mirone changed the title feat(store): add doc collection and selector feat(store): add block collection and selector Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

1 participant