extend 0.1.1
extend: ^0.1.1 copied to clipboard

A Dart port of classic `extend()` method from jQuery. Empower `Map` to be `extend()`-ed

extend Pub version GitHub #

A Dart port of classic extend() method from jQuery. It extend an existing Mutable Map with another source. It can be extended by multiple additional sources in a sequence.

Beware: the original Map will be modified and will be returned.

Example:

// Don't use `const` or `final`. It'll make the Map `Immutable`
var baseObj = {
  'dummy': 'x',
  'complex': {
    'subKey': 'subValue',
    'subComplex': {
      'deepKey': 'deepValue',
    },
    'subUndefined': null
  },
  'baseUndefined': null
};

final result = baseObj.extend({
  'complex': {
    'subKey': 'subValueOther',
    'subComplex': {'deepNewKey': 'deepNewValue'}
  },
  'newKey': 'newValue'
});
// beware, the original object is also changed
print(baseObj);
// Hence, you may discard using result
print(result);
// in case, if you have one Immutable Map or don't want to change the
// original Map, try to extend an empty Map
final result = {}.extend(baseObj, [
  {
    'complex': {
      'subKey': 'subValueOther',
      'subComplex': {'deepNewKey': 'deepNewValue'}
    },
    'newKey': 'newValue'
  }
]);

print(result);

Output:

{
  "dummy": "x",
  "complex": {
    "subKey": "subValueOther", // 👈 is extended
    "subComplex": {
      "deepKey": "deepValue", // 👈 remains unchanged
      "deepNewKey": "deepNewValue"  // 👈 is added
    },
    "subUndefined": null
  },
  "baseUndefined": null,
  "newKey": "newValue"  // 👈 is added
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0
likes
130
pub points
14%
popularity

Publisher

marganam.com

A Dart port of classic `extend()` method from jQuery. Empower `Map` to be `extend()`-ed

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

More

Packages that depend on extend