0

How do I implement continuous checking (time based) of a property-change in a component using an event listener in Polymer 3?

These are my component's properties:

static get properties() {
  return {
    longitude: {
      type: Number
    },
    latitude: {
      type: Number
    },
    accuracy: {
      type: Number
    }
  };
}
tony19
  • 125,647
  • 18
  • 229
  • 307
  • 1
    What have you tried so far and where exactly are you stuck? – Nico Haase Jul 02 '18 at 10:38
  • static get properties() { return { longitude: { type: Number }, latitude: { type: Number }, accuracy: { type: Number } }; } In this function I want to know how to check for change in longitude and latitude values( that r being passed from html code while running the component) dynamically and update the same accordingly using polymer 3. – Saksham Sondhi Jul 04 '18 at 05:43
  • 1
    Please do not add code to a comment, rather edit the question. And the given code does only return static stuff from my point of view. Where should a change be detected? – Nico Haase Jul 04 '18 at 07:08

1 Answers1

1

You could use a complex observer that is called whenever any of the specified properties change. To do this, declare an observers getter that returns a string array, where each string is the observer method name, followed by a list of dependencies (i.e., properties to be observed) in parentheses:

static get observers() {
  return ['_onPropsChanged(longitude, latitude, accuracy)'];
}

_onPropsChanged(longitude, latitude, accuracy) {
  console.log({ longitude, latitude, accuracy });
}

demo

tony19
  • 125,647
  • 18
  • 229
  • 307