@@ -8,6 +8,12 @@ namespace margelo::nitro::cssnitro {
88 std::unordered_map<std::string, VariableContext::Context> VariableContext::contexts;
99
1010 void VariableContext::createContext (const std::string &key, const std::string &parent) {
11+ // Check if context already exists
12+ if (contexts.find (key) != contexts.end ()) {
13+ // Context already exists, don't overwrite it
14+ return ;
15+ }
16+
1117 // Create a new context with the specified parent
1218 Context ctx;
1319 ctx.parent = parent;
@@ -45,6 +51,13 @@ namespace margelo::nitro::cssnitro {
4551 if (!std::holds_alternative<std::monostate>(result)) {
4652 return result;
4753 }
54+ } else {
55+ // Variable doesn't exist in this context, create a new Observable with nullptr
56+ auto observable = reactnativecss::Observable<AnyValue>::create (AnyValue ());
57+ valueMap[name] = observable;
58+
59+ // Subscribe to the observable by calling get()
60+ get (*observable);
4861 }
4962 }
5063 return std::nullopt ;
@@ -159,13 +172,13 @@ namespace margelo::nitro::cssnitro {
159172 }
160173
161174 void VariableContext::setTopLevelVariable (const std::string &key, const std::string &name,
162- const std::vector<HybridRootVariableRule> &value) {
163- // Create a new Computed that returns "yellow" for now
175+ const AnyValue &value) {
176+ // Create a new Computed that returns the provided value
164177 auto computed = reactnativecss::Computed<AnyValue>::create (
165- [](const AnyValue &prev, reactnativecss::Effect::GetProxy &get) -> AnyValue {
178+ [value ](const AnyValue &prev, reactnativecss::Effect::GetProxy &get) -> AnyValue {
166179 (void ) prev;
167180 (void ) get;
168- return AnyValue ( " yellow " ) ;
181+ return value ;
169182 },
170183 AnyValue () // Initial value
171184 );
0 commit comments