Skip to content

How to pass an initialization param to a capsule from build? #184

Closed Answered by GregoryConrad
opsb asked this question in Q&A
Discussion options

You must be logged in to vote

You cannot pass parameters to a capsule because it would no longer be a capsule (and capsules are typedefs for T Function(CapsuleHandle)). For many situations, the answer is factory capsules. There are also "dynamic capsules," but unless you need incremental computation (you will know if you need it when you need it) then you don't need it. For yours, it looks like you just want another capsule:

ValueWrapper<int> startingCountManager(CapsuleHandle use) => use.data(0);

(int, void Function()) countManager(CapsuleHandle use) {
  final count = use.data(use(startingCountManager).value);
  return (count.value, () => count.value++);
}

And just make sure to read/set the startingCountManager before

Replies: 2 comments 15 replies

Comment options

You must be logged in to vote
6 replies
@opsb
Comment options

@busslina
Comment options

@busslina
Comment options

@GregoryConrad
Comment options

@opsb
Comment options

Comment options

You must be logged in to vote
9 replies
@GregoryConrad
Comment options

@opsb
Comment options

@opsb
Comment options

@GregoryConrad
Comment options

@opsb
Comment options

Answer selected by GregoryConrad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants