Giter Club home page Giter Club logo

blaze-integration's Introduction

svelte:blaze-integration

This Meteor package makes it possible to instantiate Blaze templates inside Svelte components, with reactivity across boundaries.

This package is still experimental.

Installation

To add this package to your app, you will want to run the following command:

meteor add svelte:blaze-integration

Using Blaze inside Svelte

This package provides a <BlazeTemplate> component which will render the given Blaze template inside the Svelte component. The template is specified in the template property, which may either be a string template name or a Template reference, for example:

<script>
  import { BlazeTemplate } from 'meteor/svelte:blaze-integration';
</script>

<BlazeTemplate template="loginButtons" />
<BlazeTemplate template={Template.loginButtons} />

To pass in data, use the data prop, which will be updated reactively according to the normal Svelte rules for reactivity (ie. requiring an assignment):

<script>
  import { BlazeTemplate } from 'meteor/svelte:blaze-integration';
  import './label.html';

  let labelData = {text: 'not clicked'};

  function handleClick() {
    labelData = {text: 'clicked'};
  }
</script>

<BlazeTemplate template={Template.Label} data={labelData} />

Slotted content

You can use {{> Template.contentBlock}} as in Blaze to spawn in the slotted content inside the BlazeTemplate component.

Using Svelte inside Blaze

To render a Svelte component inside a Blaze template, use the SvelteComponent template. This works similarly to Svelte's own <svelte:component>, and takes the component as this argument and the props as remaining arguments.

MyTemplate.html

<template name="MyTemplate">
  {{> SvelteComponent this=MyComponent first="Hello" second="world"}}
</template>

MyTemplate.js

import MyComponent from './MyComponent.svelte';

Template.MyTemplate.helpers({
  MyComponent: () => MyComponent,
});

MyComponent.svelte

<script>
  export let first;
  export let second;
</script>

<p>{first} {second}!</p>

If you wish to determine the selection of props programmatically, you can use the single-argument form instead:

MyTemplate.html

<template name="MyTemplate">
  {{> SvelteComponent myHelperFunction}}
</template>

MyTemplate.js

import MyComponent from './MyComponent.svelte';

Template.MyTemplate.helpers({
  myHelperFunction() {
    return {
      this: MyComponent,
      first: "Hello",
      second: "world",
    };
  },
});

You can also directly return MyComponent, but that method will not support additional properties.

Slotted content

Slotted content (like Template.contentBlock) is also supported. For example:

MyTemplate.html

<template name="MyTemplate">
  {{#SvelteComponent this=myComponentHelper}}
    Welcome
  {{/SvelteComponent}}
</template>

Heading.svelte

<h1><slot /></h1>

blaze-integration's People

Contributors

rdb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

blaze-integration's Issues

Strange jQuery requirements

After installing and including meteor/svelte:blaze-integration I kept on getting the error below.

The only way I could resolve this was by adding jQuery to both the NPM and Meteor Package Manager. ie

> meteor add jquery (v3.0.0)
> meteor npm install jquery --save  (v3.6.0)

Without both packages installed - it produced the errors below.

I tested by only installed npm [email protected] [email protected] - nothing helped.

Uncaught Error: jQuery not found
    at module (dombackend.js:8)
    at fileEvaluate (modules-runtime-hot.js?hash=d12281259a6cee99786429a66f76b05f13449c7f:388)
    at Module.require (modules-runtime-hot.js?hash=d12281259a6cee99786429a66f76b05f13449c7f:270)
    at require (modules-runtime-hot.js?hash=d12281259a6cee99786429a66f76b05f13449c7f:310)
    at blaze.js?hash=a20deb597f76789e171a9ee2b2e37d73fbb7ecda:3735
    at blaze.js?hash=a20deb597f76789e171a9ee2b2e37d73fbb7ecda:3754
module @ dombackend.js:8
fileEvaluate @ modules-runtime-hot.js?hash=d12281259a6cee99786429a66f76b05f13449c7f:388
require @ modules-runtime-hot.js?hash=d12281259a6cee99786429a66f76b05f13449c7f:270
require @ modules-runtime-hot.js?hash=d12281259a6cee99786429a66f76b05f13449c7f:310
(anonymous) @ blaze.js?hash=a20deb597f76789e171a9ee2b2e37d73fbb7ecda:3735
(anonymous) @ blaze.js?hash=a20deb597f76789e171a9ee2b2e37d73fbb7ecda:3754
spacebars.js?hash=6f2be25813c793c0b363a6a91ebb029723f294ec:22 

Uncaught TypeError: Cannot read property 'Blaze' of undefined
    at spacebars.js?hash=6f2be25813c793c0b363a6a91ebb029723f294ec:22
    at spacebars.js?hash=6f2be25813c793c0b363a6a91ebb029723f294ec:331
(anonymous) @ spacebars.js?hash=6f2be25813c793c0b363a6a91ebb029723f294ec:22
(anonymous) @ spacebars.js?hash=6f2be25813c793c0b363a6a91ebb029723f294ec:331
templating-runtime.js?hash=9b008466a63cfaa8a7f0a8703fb4a6d8d253fb06:18 

Uncaught TypeError: Cannot read property 'Blaze' of undefined
    at templating-runtime.js?hash=9b008466a63cfaa8a7f0a8703fb4a6d8d253fb06:18
    at templating-runtime.js?hash=9b008466a63cfaa8a7f0a8703fb4a6d8d253fb06:252
(anonymous) @ templating-runtime.js?hash=9b008466a63cfaa8a7f0a8703fb4a6d8d253fb06:18
(anonymous) @ templating-runtime.js?hash=9b008466a63cfaa8a7f0a8703fb4a6d8d253fb06:252
templating.js?hash=bdb2d25c8c2ecf9a55d420f7d84e264af6b08e3d:14 

Uncaught TypeError: Cannot read property 'Template' of undefined
    at templating.js?hash=bdb2d25c8c2ecf9a55d420f7d84e264af6b08e3d:14
    at templating.js?hash=bdb2d25c8c2ecf9a55d420f7d84e264af6b08e3d:23
(anonymous) @ templating.js?hash=bdb2d25c8c2ecf9a55d420f7d84e264af6b08e3d:14
(anonymous) @ templating.js?hash=bdb2d25c8c2ecf9a55d420f7d84e264af6b08e3d:23
accounts-ui-unstyled.js?hash=f8ec028a0836ba06d7817f9bc71f5927b6c79612:21 

Uncaught TypeError: Cannot read property 'Template' of undefined
    at accounts-ui-unstyled.js?hash=f8ec028a0836ba06d7817f9bc71f5927b6c79612:21
    at accounts-ui-unstyled.js?hash=f8ec028a0836ba06d7817f9bc71f5927b6c79612:1989
(anonymous) @ accounts-ui-unstyled.js?hash=f8ec028a0836ba06d7817f9bc71f5927b6c79612:21
(anonymous) @ accounts-ui-unstyled.js?hash=f8ec028a0836ba06d7817f9bc71f5927b6c79612:1989
svelte_blaze-integration.js?hash=d391558118b59f1c1667f08fefda03b1dd5922a5:17 

Uncaught TypeError: Cannot read property 'Blaze' of undefined
    at svelte_blaze-integration.js?hash=d391558118b59f1c1667f08fefda03b1dd5922a5:17
    at svelte_blaze-integration.js?hash=d391558118b59f1c1667f08fefda03b1dd5922a5:330
(anonymous) @ svelte_blaze-integration.js?hash=d391558118b59f1c1667f08fefda03b1dd5922a5:17
(anonymous) @ svelte_blaze-integration.js?hash=d391558118b59f1c1667f08fefda03b1dd5922a5:330
modules-runtime-hot.js?hash=d12281259a6cee99786429a66f76b05f13449c7f:234 

Uncaught Error: Cannot find module 'meteor/svelte:blaze-integration'
    at makeMissingError (modules-runtime-hot.js?hash=d12281259a6cee99786429a66f76b05f13449c7f:234)
    at Module.resolve (modules-runtime-hot.js?hash=d12281259a6cee99786429a66f76b05f13449c7f:249)
    at Module.moduleLink [as link] (modules.js?hash=e15f20f9497a664398ebf20d39c5dff5c5884164:327)
    at module (app.js?hash=057a5ef895c9e7d194df12eb44d5ce8dfef71c42:122)
    at fileEvaluate (modules-runtime-hot.js?hash=d12281259a6cee99786429a66f76b05f13449c7f:388)
    at Module.require (modules-runtime-hot.js?hash=d12281259a6cee99786429a66f76b05f13449c7f:270)
    at Module.moduleLink [as link] (modules.js?hash=e15f20f9497a664398ebf20d39c5dff5c5884164:334)
    at module (main.js:1)
    at fileEvaluate (modules-runtime-hot.js?hash=d12281259a6cee99786429a66f76b05f13449c7f:388)
    at Module.require (modules-runtime-hot.js?hash=d12281259a6cee99786429a66f76b05f13449c7f:270)

Using Blaze Integration with autoform is failing

Cannot read property 'constructView' of null

<script>
    import { BlazeTemplate } from 'meteor/svelte:blaze-integration'
    import {ScheduleCollection} from "../api/schedule";

    let formConfig =  {
        id:"insertNewScheduleForm",
        type:"insert",
        collection:"ScheduleCollection"
    }
</script>

<div>
    Hello
    <BlazeTemplate template="quickForm" data={formConfig} />
 </div>

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.