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

fix: set currentSpace inside addSpace if currentSpace isn't set #575

Closed
wants to merge 1 commit into from

Conversation

travis
Copy link
Member

@travis travis commented Mar 20, 2023

I noticed this wasn't happening because w3ui's w3console was in a state where the space picker was populated with many spaces, but currentSpace wasn't set.

I think we should avoid this situation at this level because it's most convenient for me, but open to moving this assurance to another level if.

I noticed this wasn't happening because w3ui's w3console was in a state where the space picker was populated with many spaces, but currentSpace wasn't set.

I think we should avoid this situation at this level because it's most convenient for me, but open to moving this assurance to another level if.
@travis travis requested review from alanshaw, Gozala and gobengo March 20, 2023 20:10
* @param {import('./types').SpaceMeta} meta
* @param {import('@ucanto/interface').Delegation} [proof]
*/
async addSpace(did, meta, proof) {
this.spaces.set(did, meta)
if (!this.currentSpace) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not obvious to me that calling addSpace would also have the side effect of changing this.currentSpace, either from the comments or tests.

Why should this have that side effect, instead of leaving this to the caller to decide whether or not to call Agent#setCurrentSpace? The latter seems like the most flexible solution.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and, even if it is desirable to introduce the side effect here, why would this do it via assigning this.currentSpace = vs calling this.setCurrentSpace?)

@@ -111,12 +111,15 @@ export class AgentData {

/**
* @deprecated
* @param {import('@ucanto/interface').DID} did
* @param {import('@ucanto/interface').DID<'key'>} did
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be useful to indicate which did (space). (e.g. it might be ambiguous considering the proof @param itself is composed of several DIDs)

@@ -754,7 +754,7 @@ export async function addSpacesFromDelegations(access, delegations) {

for (const [did, value] of Object.entries(allows)) {
if (did.startsWith('did:key') && value['space/*']) {
data.addSpace(/** @type {Ucanto.DID} */ (did), {
data.addSpace(/** @type {Ucanto.DID<'key'>} */ (did), {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be awaited.

* @param {import('./types').SpaceMeta} meta
* @param {import('@ucanto/interface').Delegation} [proof]
*/
async addSpace(did, meta, proof) {
this.spaces.set(did, meta)
if (!this.currentSpace) {
this.currentSpace = did
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side effects make me nervous. I'd feel better about it if the agent class called setCurrent after adding a space(s)...at this level there's no choice for anyone using the data class.

Please if you decide not to move then can you at least add a comment to the method in the agent class to say that it will set current space if one is not set? 🙏

@travis
Copy link
Member Author

travis commented Mar 20, 2023

eh, if both of you feel like adding this here is too icky I'm not gonna do it - will find another place to do this!

@travis travis closed this Mar 20, 2023
@alanshaw
Copy link
Member

FWIW I think you made the right decision 😘

@travis
Copy link
Member Author

travis commented Mar 21, 2023

thanksssss me too, thx to both of you for pushing this in the right direction!

Peeja pushed a commit to storacha/upload-service that referenced this pull request Jan 17, 2025
🤖 I have created a release *beep* *boop*
---


##
[6.0.0](storacha/w3ui@solid-keyring-v5.0.1...solid-keyring-v6.0.0)
(2023-11-21)


### ⚠ BREAKING CHANGES

* use w3up-client in keyring
([storacha#581](storacha/w3ui#581))

### Features

* add support for getting an account's plan
([storacha#564](storacha/w3ui#564))
([11023a4](storacha/w3ui@11023a4))
* re-export Service from `react-keyring`
([storacha#577](storacha/w3ui#577))
([308816d](storacha/w3ui@308816d))
* use w3up-client in keyring
([storacha#581](storacha/w3ui#581))
([bd5f341](storacha/w3ui@bd5f341))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Travis Vachon <[email protected]>
Peeja pushed a commit to storacha/upload-service that referenced this pull request Jan 29, 2025
🤖 I have created a release *beep* *boop*
---


##
[6.0.0](storacha/w3ui@solid-keyring-v5.0.1...solid-keyring-v6.0.0)
(2023-11-21)


### ⚠ BREAKING CHANGES

* use w3up-client in keyring
([storacha#581](storacha/w3ui#581))

### Features

* add support for getting an account's plan
([storacha#564](storacha/w3ui#564))
([9565452](storacha/w3ui@9565452))
* re-export Service from `react-keyring`
([storacha#577](storacha/w3ui#577))
([94e8b96](storacha/w3ui@94e8b96))
* use w3up-client in keyring
([storacha#581](storacha/w3ui#581))
([2edddd9](storacha/w3ui@2edddd9))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Travis Vachon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants