pub fn render_to_string(source: &str, entry_point: &str, params: Option<&str>) -> String {
        Self::init_platform();

        {
            //The isolate rapresente an isolated instance of the v8 engine
            //Object from one isolate must not be used in other isolates.
            let isolate = &mut v8::Isolate::new(Default::default());

            //A stack-allocated class that governs a number of local handles.
            let handle_scope = &mut v8::HandleScope::new(isolate);

            //A sandboxed execution context with its own set of built-in objects and functions.
            let context = v8::Context::new(handle_scope);

            //Stack-allocated class which sets the execution context for all operations executed within a local scope.
            let scope = &mut v8::ContextScope::new(handle_scope, context);

            let code = v8::String::new(scope, &format!("{};{}", source, entry_point))
                .expect("Strings are needed");

            let script =
                v8::Script::compile(scope, code, None).expect("There aren't runnable scripts");

            let exports = script
                .run(scope)
                .expect("Missing entry point. Is the bundle exported as a variable?");

            let object = exports.to_object(scope).expect("There are no objects");

            let fn_map = Self::create_fn_map(scope, object);

            let params: v8::Local<v8::Value> = match v8::String::new(scope, params.unwrap_or("")) {
                Some(s) => s.into(),
                None => v8::undefined(scope).into(),
            };

            let undef = v8::undefined(scope).into();

            let mut rendered = String::new();

            for key in fn_map.keys() {
                let result = fn_map[key]
                    .call(scope, undef, &[params])
                    .expect("Are provided all needed props?");

                let result = result.to_string(scope).unwrap();

                rendered = format!("{}{}", rendered, result.to_rust_string_lossy(scope));
            }

            rendered
        }
    }
/// Evaluates the javascript source code passed and runs the render functions.
/// Any initial params (if needed) must be passed as JSON.
///
/// <a href="https://github.com/Valerioageno/ssr-rs/blob/main/examples/actix_with_initial_props.rs" target="_blank">Here</a> an useful example of how to use initial params with the actix framework.
///
/// "enrty_point" is the variable name set from the frontend bundler used. <a href="https://github.com/Valerioageno/ssr-rs/blob/main/client/webpack.ssr.js" target="_blank">Here</a> an example from webpack.
Evaluates the javascript source code passed and runs the render functions.
Any initial params (if needed) must be passed as JSON.

Here an useful example of how to use initial params with the actix framework.

"enrty_point" is the variable name set from the frontend bundler used. Here an example from webpack.
Evaluates the javascript source code passed and runs the render functions . Any initial params ( if needed ) must be passed as JSON . Here an useful example of how to use initial params with the actix framework . " enrty_point " is the variable name set from the frontend bundler used . Here an example from webpack .
pub fn render_to_string(source: &str, entry_point: &str, params: Option<&str>) -> String {
        Self::init_platform();
        {
            //The isolate rapresente an isolated instance of the v8 engine
            //Object from one isolate must not be used in other isolates.
            let isolate = &mut v8::Isolate::new(Default::default());
            //A stack-allocated class that governs a number of local handles.
            let handle_scope = &mut v8::HandleScope::new(isolate);
            //A sandboxed execution context with its own set of built-in objects and functions.
            let context = v8::Context::new(handle_scope);
            //Stack-allocated class which sets the execution context for all operations executed within a local scope.
            let scope = &mut v8::ContextScope::new(handle_scope, context);
            let code = v8::String::new(scope, &format!("{};{}", source, entry_point))
                .expect("Strings are needed");
            let script =
                v8::Script::compile(scope, code, None).expect("There aren't runnable scripts");
            let exports = script
                .run(scope)
                .expect("Missing entry point. Is the bundle exported as a variable?");
            let object = exports.to_object(scope).expect("There are no objects");
            let fn_map = Self::create_fn_map(scope, object);
            let params: v8::Local<v8::Value> = match v8::String::new(scope, params.unwrap_or("")) {
                Some(s) => s.into(),
                None => v8::undefined(scope).into(),
            };
            let undef = v8::undefined(scope).into();
            let mut rendered = String::new();
            for key in fn_map.keys() {
                let result = fn_map[key]
                    .call(scope, undef, &[params])
                    .expect("Are provided all needed props?");
                let result = result.to_string(scope).unwrap();
                rendered = format!("{}{}", rendered, result.to_rust_string_lossy(scope));
            }
            rendered
        }
    }
pub fn render_to_string ( source : & str , entry_point : & str , params : Option < & str > ) -> String { Self :: init_platform ( ) ; { //The isolate rapresente an isolated instance of the v8 engine //Object from one isolate must not be used in other isolates. let isolate = & mut v8 :: Isolate :: new ( Default :: default ( ) ) ; //A stack-allocated class that governs a number of local handles. let handle_scope = & mut v8 :: HandleScope :: new ( isolate ) ; //A sandboxed execution context with its own set of built-in objects and functions. let context = v8 :: Context :: new ( handle_scope ) ; //Stack-allocated class which sets the execution context for all operations executed within a local scope. let scope = & mut v8 :: ContextScope :: new ( handle_scope , context ) ; let code = v8 :: String :: new ( scope , & format ! ( " " source entry_point ) ) . expect ( " " ) ; let script = v8 :: Script :: compile ( scope , code , None ) . expect ( " " ) ; let exports = script . run ( scope ) . expect ( " " ) ; let object = exports . to_object ( scope ) . expect ( " " ) ; let fn_map = Self :: create_fn_map ( scope , object ) ; let params : v8 :: Local < v8 :: Value > = match v8 :: String :: new ( scope , params . unwrap_or ( " " ) ) { Some ( s ) => s . into ( ) , None => v8 :: undefined ( scope ) . into ( ) , } ; let undef = v8 :: undefined ( scope ) . into ( ) ; let mut rendered = String :: new ( ) ; for key in fn_map . keys ( ) { let result = fn_map [ key ] . call ( scope , undef , & [ params ] ) . expect ( " " ) ; let result = result . to_string ( scope ) . unwrap ( ) ; rendered = format ! ( " " rendered result to_rust_string_lossy ( scope ) ) ; } rendered } }
Evaluates the javascript source code passed and runs the render functions.
Evaluates the javascript source code passed and runs the render functions .
source
&str
entry_point
&str
params
Option<&str>
source
&str
entry_point
&str
params
Option<&str>