Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add declarative way to set up observers and event listeners #1042

Closed
PaulMaly opened this issue Dec 22, 2017 · 5 comments
Closed

Add declarative way to set up observers and event listeners #1042

PaulMaly opened this issue Dec 22, 2017 · 5 comments

Comments

@PaulMaly
Copy link
Contributor

PaulMaly commented Dec 22, 2017

I think we really need to have a declarative way to set up observers and event listeners. It could be implemented just like Ractive does:

observe: {
    show ( value, old ) {

    },
    users: {
      handler ( value, old ) {

      },
      init: false,
      strict: true
    }
  },
  on: {
    create () {

    },
    somethingHappened: {
      handler ( ctx ) {
      },
      once: true
    }
  }
}
@PaulBGD
Copy link
Member

PaulBGD commented Dec 25, 2017

I think adding event listeners is super useful, as most event listeners I use in a component immediately call a method in methods anyways, so I really like the idea of just telling it which event listener to use (and also being able to pass options is important!)

@PaulMaly
Copy link
Contributor Author

@Rich-Harris Any updates here? I think this solution gives us the way to keep our oncreate hook is clean.

@jacwright
Copy link
Contributor

If we implemented on would we move oncreate and ondestroy into it if they are still needed?

export default {
  on: {
    create() {
      // setup
    },
    destroy() {
      // setup
    }
  }
};

I like the observe. Not sure about on. And I'm getting along fine without either so far and not feeling my code is too messy.

@PaulMaly
Copy link
Contributor Author

PaulMaly commented Mar 30, 2018

@jacwright In Ractive all life-cycle hooks available like regular custom events. And able to be listened from the parent:

<Widget on:init="..." /> 

@Rich-Harris
Copy link
Member

Closing as this isn't applicable to Svelte 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants