Skip to content

Commit

Permalink
Updating can-define/map documentation (#382)
Browse files Browse the repository at this point in the history
* updated example to es6 to prototype.assign.md

* Updated example to ES6 syntax. Added link to codepen.

* Updated examples, Added a use section hoping to elaborate what happens when deleteKey is called on a pre-defined property.

* Updated to ES6 syntax. Made codepen-able. Added some documentation to the Use section focused on returning false. Moved the initial example to the signature.

* Updated syntax and and added codepen link.

* updated to ES6. It now links to codepen.

* updateDeep is ES6. It now links to codepen.

* Changed from single to double quote to match other examples.

* added codepen example to the non deprecated use of set.

* get has es6 codepenable examples.

* Syntax, ES6 and link to codepen added. Commented on issue #378 for map/KeysEvent.html stating that events.keys.md is a stub.

* updated events.keys.md spacing

* events.propertyName.md updated example.

* updated syntax and linked to codepen. Also threw them down to a use section, though it might be suggested to change them to separate signatures.

* fixed spacing error in static.extend.md

* major updates to define-map.md documentation.

* added syntax highlighting and updated to es6 syntax for wildcard.

* working es6 codepen-able example on static.seal.md

* minor cleanup

* some additional fixes

* use any now for accepting any type

* updated assign and assignDeep to more mirror their counterparts in list/list.

* codepen updates across map.

* Updated and fixed spelling errors.
  • Loading branch information
indifferentghost authored Sep 4, 2018
1 parent aeb480e commit 95f4739
Show file tree
Hide file tree
Showing 15 changed files with 592 additions and 311 deletions.
44 changes: 36 additions & 8 deletions docs/deleteKey.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,45 @@

@signature `map.deleteKey(key)`

Deletes a key that was added to an instance, but not pre-defined by the type.
Deletes a key that was added to an instance, but not pre-defined by the type.

```js
import {DefineMap, Reflect} from "can";

const map = new DefineMap( {propA: "valueA"} );
console.log( map.propA ); //-> "valueA"

map.deleteKey("propA");
console.log( map.propA ); //-> undefined
```
@codepen

@param {String} key A string of the key being deleted.

@return {can-define/map/map} The map instance for chaining.

@body

## Use

If `deleteKey` is called on a pre-defined type it sets the value to `undefined`. This is to keep the setters and getters on all instances of that Type.

```js
import {DefineMap} from "can";
import {DefineMap, Reflect} from "can";

var Type = DefineMap.extend({seal: false},{
propA: "string"
});
const Type = DefineMap.extend(
{seal: false},
{
propA: "string"
}
);

var map = new Type({propA: "valueA"});
const map = new Type( {propA: "valueA"} );
map.set("propB","valueB");
map.deleteKey("propB"); // this works.
map.deleteKey("propA"); // this does not work.
map.deleteKey("propB"); // This works.
map.deleteKey("propA"); // This doesn't delete the key, but does set the key to undefined.

console.log( Reflect.getOwnKeys(map) ); //-> ["propA"]
console.log( map.propA ); //-> undefined
```
@codepen
Loading

0 comments on commit 95f4739

Please sign in to comment.