Terran-Source / dart-extend

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

Home Page:https://pub.dev/packages/extend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

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

https://pub.dev/packages/extend

License:MIT License


Languages

Language:Dart 100.0%