Giter VIP home page Giter VIP logo

ember-compatibility-helpers's Introduction

Build Status npm version

ember-compatibility-helpers

Provides flags for features in Ember, allowing you to write code that will work with whatever version the consuming application is on. This addon is intended to help addon authors write backwards/forwards compatibility code.

The flags are replaced at build time with boolean literals (true or false) by a Babel transform. When ran through a minifier (with dead code elimination) the entire section will be stripped, meaning that the section of code which is not used will not be added to production builds - zero cost compatibility!

Installation

ember install ember-compatibility-helpers

Available Flags

import {
  // General functions for checking against Ember version
  gte,
  lte,

  // Flags for specific Ember functionality
  HAS_UNDERSCORE_ACTIONS,
  HAS_MODERN_FACTORY_INJECTIONS,

  IS_GLIMMER_2,
  IS_RECORD_DATA,

  SUPPORTS_FACTORY_FOR,
  SUPPORTS_GET_OWNER,
  SUPPORTS_SET_OWNER,
  SUPPORTS_NEW_COMPUTED,
  SUPPORTS_INVERSE_BLOCK,
  SUPPORTS_CLOSURE_ACTIONS,
  SUPPORTS_UNIQ_BY_COMPUTED
} from 'ember-compatibility-helpers';

More welcome, open an issue or a PR!

Version Identifiers

Version strings passed to version checker functions, such as gte or lte, must be fully qualified versions. Version ranges or shorthands are not supported.

// Do this:
lte('3.13.0-beta.1')

// Not this:
lte('3.12'); // won't work!
lte('^3.12.0'); // won't work!

Example Usage

Function usage:

import Component from '@ember/component';
import { computed } from '@ember/object';

import { gte } from 'ember-compatibility-helpers';

export default Component.extend({
  foo: computed({
    get() {
      return 'bar';
    }
  }),

  baz: computed({
    get() {
      // checks version against ember-source
      if (gte('3.1.0')) {
        return this.foo;
      } else {
        return this.get('foo');
      }
    }
  }),
  
  boo() {
    if (gte('my-addon-name', '3.5.0-beta.3')) {
      return {};
    } else {
      return Ember.Object.create({});
    }
  }
});

Flag usage:

import Component from '@ember/component';
import { computed } from '@ember/object';

import { SUPPORTS_NEW_COMPUTED } from 'ember-compatibility-helpers';

function fooMacro() {
  if (SUPPORTS_NEW_COMPUTED) {
    return computed({
      get() {
        return this.get('foo');
      },

      set(key, value) {
        this.set('foo', value);
        return value
      }
    });
  } else {
    return computed(function(key, value) {
      if (arguments.length === 2) {
        this.set('foo', value);
        return value;
      }

      return this.get('foo');
    })
  }
}

export default Component.extend({
  bar: fooMacro()
});

Development

  • git clone <repository-url> this repository
  • cd ember-compatibility-helpers
  • yarn

Running Tests

  • npm test

ember-compatibility-helpers's People

Contributors

pzuraq avatar rwjblue avatar runspired avatar alexlafroscia avatar stefanpenner avatar buschtoens avatar simonihmig avatar tomdale avatar ember-tomster avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.