Replace a resource from another existing resource to test hot reloading.
| 176 | |
| 177 | // Replace a resource from another existing resource to test hot reloading. |
| 178 | Result<Void> RuntimeWrapper::hotReload(const char* sourceResourcePath, const char* destResourcePath) { |
| 179 | auto resourceId = Valdi::JavaScriptPathResolver::resolveResourceId(STRING_LITERAL(sourceResourcePath)); |
| 180 | if (!resourceId) { |
| 181 | return resourceId.moveError(); |
| 182 | } |
| 183 | |
| 184 | auto bundle = runtime->getResourceManager().getBundle(resourceId.value().bundleName); |
| 185 | |
| 186 | auto jsResult = bundle->getJs(resourceId.value().resourcePath); |
| 187 | if (!jsResult) { |
| 188 | return jsResult.moveError(); |
| 189 | } |
| 190 | |
| 191 | auto destResourceId = Valdi::JavaScriptPathResolver::resolveResourceId(STRING_LITERAL(destResourcePath)); |
| 192 | if (!destResourceId) { |
| 193 | return destResourceId.moveError(); |
| 194 | } |
| 195 | |
| 196 | auto jsResource = ResourceId(destResourceId.value().bundleName, destResourceId.value().resourcePath.append(".js")); |
| 197 | |
| 198 | hotReload(jsResource, jsResult.value().content); |
| 199 | |
| 200 | return Void(); |
| 201 | } |
| 202 | |
| 203 | void RuntimeWrapper::hotReload(const Valdi::StringBox& bundleName, |
| 204 | const Valdi::StringBox& path, |
no test coverage detected