Giter VIP home page Giter VIP logo

blazorjsembedder's Introduction

Blazor JavaScript Embedder Nuget BlazorJsEmbedder package

โš ๏ธ This is still work in progress

This repository allows you to write your JavaScript codes in razor file.

If you want run JavaScript codes at first render, you can use JsEmbedder component:

<JsEmbedder
            @ref="ref"
            JavaScript="
                alert('Hello Blazor Javascript Embedder!')
           "/>

Also you can use RunJsFunction<T> method to run javascript functions inside your C# methods:

JsEmbedder ref;
public async Task ButtonClick()
{
       var result = await ref.RunJsFunction<int>(@"
                (function() {
                    return 2 + 2;
                })()
            ");
}

Why

This repository is not doing something magical. It just use IJSRuntime. But a separate javascript file can sometimes be too complex for small jobs. With Blazor JavaScript Embedder you can directly write your JavaScript code in same file with your razor code.

Setup

There is no nuget package yet.

  1. Add nuget package to project:
dotnet add package BlazorJsEmbedder
  1. Add this script to end of _Host.cshtml:
<script src="_content/BlazorJsEmbedder/index.js"></script>

Known limitations

  • You can't debug your code with ease. Because of that I suggest use this component for not complex javascript codes.

Licensing

Licensed under the MIT.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.