/minimvc

kentarick 2019

Primary LanguageJavaScriptMIT LicenseMIT

minimvc

minimvc is a 2019 version of Kentarick, it works on node and on browsers. Browser compatibility is ie 11 above, which is ok in 2019.

minimvc provides just as little abstraction as it's needed to separate your code, it exports three classes Model, View and Controller.

All of three are just Empty classes extending the same base classes which provides with these methods:

  • constructor
  • wire
  • trigger
  • unwire

constuctor

This is where the magic happens, each property passed to the constructor automatically creates a getter and a setter, the setter raise an event with the name of the property after setting it, the event passes an object in the form of {value, previous}

wire

wire allows to wire to any of the events a class can trigger

trigger

a manual trigger for an event.

unwire

unwire previously registered events with wire

Little explaination:

While any class can listen and react to events, the best approach I can suggest is to have a controller in which you'll be only using the trigger method.

Have your models providing a setter method so that wire can make your views listening for that event and updating accordingly.

For complex views that requires more than a single field, you can access the entire wired object from the passed wired property.

You can also unwire by calling unwire with the same parameters.