ManuelDeLeon / viewmodel

MVVM for Meteor
https://viewmodel.org
MIT License
205 stars 23 forks source link

Using Signals in Mixins #266

Closed arggh closed 8 years ago

arggh commented 8 years ago

Does ViewModel support (or are you planning on supporting?) using Signals from Mixins?

I have developed a situation, where I'm trying to capture an event from the document in a ViewModel Mixin.

I had the same behaviour in multiple templates and it worked, but if I refactor the common parts into a Mixin, then the Signal stops working.

ManuelDeLeon commented 8 years ago

Try to make a repro. The following works fine:

import { Template } from 'meteor/templating';
import './main.html';

ViewModel.signal({
  mouse: { 
    mousePosition: { 
      target: document,
      event: 'mousemove',
      transform: function(event) {
        return {
          x: event.x,
          y: event.y
        }
      },
      throttle: 50
    }
  }
});

ViewModel.mixin({
  test: {
    signal: 'mouse'
  }
})

Template.example.viewmodel({
  mixin: 'test'
});
<body>
  {{> example}}
</body>

<template name="example">
  <p {{b "text: 'Mouse Position: ' + mousePosition.x + ',' + mousePosition.y"}}></p>
</template>
arggh commented 8 years ago

Here you go: https://github.com/arggh/signal-mixin-issue

Instructions are in client/main.js, but it basically seems to boil down to using Mixin-scope.

arggh commented 8 years ago

Also, changing mixin: { myMixin: 'myMixin' } to mixin: 'myMixin' and adjusting the rest accordingly fixes it in my actual app as well.

ManuelDeLeon commented 8 years ago

This one will take a bit more work than I expected...

ManuelDeLeon commented 8 years ago

Pick up 5.0.0