-1

I need to work on a project, that needs legacy support. How would I go about integrating it with modernizr to only load legacy if necessary? Is that even possible?

SimonEritsch
  • 1,047
  • 1
  • 8
  • 22

1 Answers1

1

The legacy build includes polyfills for a few bits and pieces that aren't in IE8 - Ractive does its own check when it first loads, and throws an error if it detects missing features (and it's the non-legacy build). The detection code is here - so you could just copy that into your app:

function useRactiveLegacy () {
  return (
    typeof Date.now !== FUNCTION                 ||
    typeof String.prototype.trim !== FUNCTION    ||
    typeof Object.keys !== FUNCTION              ||
    typeof Array.prototype.indexOf !== FUNCTION  ||
    typeof Array.prototype.forEach !== FUNCTION  ||
    typeof Array.prototype.map !== FUNCTION      ||
    typeof Array.prototype.filter !== FUNCTION   ||
    ( typeof window !== 'undefined' && typeof window.addEventListener !== FUNCTION )
  );
}

// using Modernizr
Modernizr.load({
  test: !useRactiveLegacy(),
  yep:  'ractive.js',
  nope: 'ractive-legacy.js
});

// using AMD
require([ useRactiveLegacy() ? 'ractive-legacy' : 'ractive' ], function ( Ractive ) {
  /* code goes here */
});

Bear in mind that these checks could change with future versions of Ractive - for example, there may come a time when we decide to relegate Promises to the legacy version, rather than automatically polyfilling it.

Rich Harris
  • 28,091
  • 3
  • 84
  • 99