Package Instantiation (Web3
, Standalone Packages, and .use
Functionality)
#4653
Replies: 3 comments
-
In current architecture option 1 and 2 are supported. For option 3 need some refacing for the context class but it's doable. Will share the idea later. |
Beta Was this translation helpful? Give feedback.
-
The earlier discussed functional approach was allowing us to create single global context and pass it around the functions. But in current 4.x rewrite as we moved to class based implementation, each package contains and initiate it's own context. So even for #1 and #3 its not true that there is a global state. |
Beta Was this translation helpful? Give feedback.
-
Initial implementation of the idea #4788 |
Beta Was this translation helpful? Give feedback.
-
A user should have 3 methods of instantiating/using Web3 packages:
Web3
class which contains all of the Web3 sub packagesWeb3Core
which contains the bare minimum structure for Web3 to function (including Web3Context), which then allows for sub packages to be appended onto theWeb3Core
instance to make use ofWeb3Context
,requestManager
, etc.In method #2, each sub package allows for the specification of a custom
Web3Context
. While flexible, if a change is made to one sub package'sWeb3Context
(changing a default value, updating the provider, etc.), none of the other sub package'sWeb3Context
s will be affectedIn method #1 and #3, the
Web3Context
is managed as global state for all the sub packages via the top level package (Web3
andWeb3Core
), and if changes are made toWeb3Context
, the global state is updated, and every sub package will be able to listen for the value changes which are emitted using Node's event emitterBeta Was this translation helpful? Give feedback.
All reactions