Moving Back to Meteor Development

Yes, that’s what I ment. Thank you for sharing your experience. I was going to take a closer look to Svetle back in December, after your post in the similar topic, now it happened. The framework definitely looks very promising.

Hello meteor/svelte users, I’d be interested in how you are handling routing? Are you using a svelte specific router? Thanks

I agree, blaze is simple compared to react imo, but every-time I try to use and add atmosphere packages I run in to problems and no solutions wrt compatibility issues. So as good as blaze is I have concluded react is best and can be used in many other frameworks and environment including mobile with react native.

1 Like

I think one of the major drawbacks using Blaze after using React is relying on helpers whereas in React (or Svelte) you get the full power of JS inside your templates.

For ease though it’s hard to beat Blaze + ViewModel. ViewModel’s mixins alone make my templates so much easier to write

Svelte is very much router-agnostic. In one of our apps we use ostrio:flow-router-extra, since we also use Blaze in the same app. In another app we’re using our custom “router”, as there’s only ~5 routes. Our third Svelte app is a Sapper export, a static site, and that’s using the filesystem based router included in Sapper. There’s also a bunch of “designed for Svelte” routers, but you can also just use page.js, or if you want a really tiny router, try Navaid.

1 Like

Cool thanks!

Just starting out now, and running into a 'target' is a required option. Frustrating! I’ve read that the npm and meteor versions need to match (which I think they do), anyone run into this?

Thanks!

Did you instantiate your app like this…

const appEl = document.getElementById('app');
const app = new App({
  target: appEl
});

…making sure, that you have an element in DOM with id="app"?

Am using:

import { Meteor } from 'meteor/meteor'
import App from './components/App.svelte'

Meteor.startup(() => {
   new App({
     target: document.querySelector('#root')
   })
})
<!-- main.html -->

<head>
  <title>meteor-svelte</title>
</head>

<body>
  <div id="root"></div>
</body>
<!-- App.svelte -->
<p>Hello Meteor Svelte!</p>

I have a version working by cloning https://github.com/meteor-svelte/tracker-example

Albeit at 3.0.0 not sure if I was trying to use an incompatible version?

What do you mean here? Do you not get the full power of JS in Blaze helpers?

Sorry I meant to suggest that you’d have to extract any such JS logic to template helpers, whereas in React/Svelte you could do it inline <p>1 + 1 = {1 + 1}</p>

1 Like

ahh, got it. Yeah, that is a little frustrating

Struggling to get any of the routers (svelte-routing or svero) working with my setup. Svero seems to bring back the target error and svelte-routing seems to cause all sort of errors, possibly due to it needing server-side configuration too.

Has anyone had any experience getting either of these (or similar) routers working with Svelte? Thanks!

Navaid was simple to setup and is very minimal in terms of the API, so if it covers your requirements I’d give that a try. Can’t say why the others wouldn’t work - sounds strange and I’d first look into making sure the version of Svelte used by svelte:compiler matches the version of Svelte in your app - take a peek inside node_modules/svelte/package.json and verify you have the correct version installed?

As an alternative, I’ve been using a component for this purpose.

// Tracker.svelte

<script>
  import { Tracker } from 'meteor/tracker';
  import { Meteor } from 'meteor/meteor';
  import { onDestroy } from 'svelte';

  export let deps = [];
  export let fn;
  const dep = new Tracker.Dependency;

  $: {
    deps;
    dep.changed();
  }

  const computation = Tracker.autorun(() => {
    dep.depend();
    fn();
  });

  onDestroy(() => {
    computation.stop();
  })
</script>

<slot></slot>

Then you’d use it as a wrapper,

<script>
  export let id;
  let model;
  function computation() {
    model = Model.findOne({ _id: id });
  }
</script>
<Tracker deps={[id]} fn={computation}>
  <h1>{model.name}</h1>
</Tracker>

Though I’ll admit, I only did it this way because I thought onDestroy had to be inside a component.

Thanks, I must confess to be unsure how to best ensure that the versions match. I’m pretty sure I specified the version when installing but now find they are slightly out. Can I just update the version number inside .meteor/packages or is it best to do it in the .package.json? Are there any other commands to run to ensure they update? Thanks!

Incidentally I also got a version of navaid working nicely using the author’s svelte-demo https://github.com/lukeed/svelte-demo although I’m not sure if it’s possible using navaid to navigate programatically?

Thanks again

You want the npm package to match the meteor package. So get the meteor package up to date, and then lock the npm version with meteor npm install svelte@<version.

Regarding routing, I use svelte-routing in my app with no issues. No special setup.

Make sure you meteor remove blaze-html-templates and meteor add static-html. You want to serve the static main.html so you can document.querySelector it. That should fix you target required error.

1 Like

Thanks! Can I just check if the version ends with _1 should that also be specified in the npm version or is that bit dropped? Eg current latest package is 3.6.7_1. TIA :+1:

That bit is dropped. So you’ve run meteor npm install svelte@3.6.7.

I have yes. (thought I got that right).

Your other tip about adding/remove the HTML packages seems to have sorted it! Thanks, I didn’t notice that in the package readme but perhaps I should have thought of it! Thanks :smile:

Might also help with the router issues?