flekschas / svelte-simple-modal

A simple, small, and content-agnostic modal for Svelte v3 and v4
https://svelte.dev/repl/b95ce66b0ef34064a34afc5c0249f313
MIT License
422 stars 30 forks source link

Broken store demo when using bind #76

Closed bewards closed 2 years ago

bewards commented 2 years ago

demo: https://svelte.dev/repl/aec0c7d9f5084e7daa64f6d0c8ef0209?version=3.48.0

I can also produce this locally using rollup.

flekschas commented 2 years ago

Oh damn, this must be caused by https://github.com/flekschas/svelte-simple-modal/commit/17663ad36c33c6292f442cce4518a414c64a80d4

Thanks for bringing this up!

bewards commented 2 years ago

I had to set up my local the following way to get it to work:

gulp

rollup({
  input: "app/scripts/main.ts",
  plugins: [
    rollupPluginSvelte({
      // Tell the svelte plugin where our svelte files are located
      include: [
        'app/**/*.svelte', 
        'node_modules/svelte-simple-modal/src/*.svelte',
      ],

Modal.svelte import Modal, { bind } from 'svelte-simple-modal/src/Modal.svelte';

flekschas commented 2 years ago

Yeah the problem is the missing export of bind which I removed to get sveld to work.

bewards commented 2 years ago

Also worth noting that importing bind in a normal typescript file (to use as a store) has the same error as the demo and my above solution doesn't work for non-svelte files

ModalStore.ts

import { writable } from 'svelte/store';
import { bind } from 'svelte-simple-modal';

const modal = writable(null);

export const showGlobalModalWithComponentProps = (component: any, props: Record<string, any>) => {
    return modal.set(bind(component, props));
}
bewards commented 2 years ago

Is there anything I can do locally to get this working, such as copying the bind function? Or are there pieces of that that rely on the the svelte file?

flekschas commented 2 years ago

You can use the previous version (v1.3.1). It contains a TypeScript error but you can ignore that error.

flekschas commented 2 years ago

I just pushed a fix to master. Could do me a favor and test if the latest version of master works for you?

bewards commented 2 years ago

Trying to install master via npm with the following command but it's not working:

npm install --save flekschas/svelte-simple-modal#master --force

I'll download manually and check

flekschas commented 2 years ago

You can also try the following:

git clone https://github.com/flekschas/svelte-simple-modal
cd svelte-simple-modal
npm install
npm build
npm pack
cd ../<your-application>
npm install ../svelte-simple-modal/svelte-simple-modal-1.3.2.tgz
bewards commented 2 years ago

@flekschas confirmed master works with bind - I just pulled down master and ran npm run build with git bash to generate the lib/src/type folders and swapped those out with my local package.

flekschas commented 2 years ago

Thanks for testing! New version (v1.3.3) is out. Could you double check that it works?

bewards commented 2 years ago

Confirmed v1.3.3, thank you @flekschas - this can be closed.