Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

can-map

Package Overview
Dependencies
Maintainers
4
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

can-map

Observable Objects

  • 3.0.0-pre.11
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
decreased by-29.75%
Maintainers
4
Weekly downloads
 
Created
Source

can-map

Build Status

Observable Objects

API

can-map

Create observable objects.

new Map([props])

Creates a new instance of can.Map.

  1. props {Object}: Properties and values to seed the Observe with.
  • returns {can.Map}: An instance of can.Map with the properties from props.

Map.extend([name,] [staticProperties,] instanceProperties)

Creates a new extended constructor function.

map.attr()

Gets a collection of all the properties in this Map.

  • returns {Object}: an object with all the properties in this Map.
map.attr(key)

Reads a property from this Map.

  1. key {String}: the property to read
  • returns {*}: the value assigned to key.
map.attr(key, value)

Assigns value to a property on this Map called key.

  1. key {String}: the property to set
  2. the {*}: value to assign to key.
  • returns {can.Map}: this Map, for chaining
map.attr(obj[, removeOthers])

Assigns each value in obj to a property on this Map named after the corresponding key in obj, effectively merging obj into the Map.

  1. obj {Object}: a collection of key-value pairs to set. If any properties already exist on the Map, they will be overwritten.

  2. removeOthers {bool}: whether to remove keys not present in obj. To remove keys without setting other keys, use [can.Map::removeAttr removeAttr].

  • returns {can.Map}: this Map, for chaining
map.bind(eventType, handler)
  1. eventType {String}: the type of event to bind this handler to
  2. handler {function}: the handler to be called when this type of event fires The signature of the handler depends on the type of event being bound. See below for details.
  • returns {can.Map}: this Map, for chaining
map.compute(attrName)
  1. attrName {String}: the property to bind to
  • returns {can-compute}: a [can-compute] bound to attrName
DEFAULT-ATTR {*}

Specify a default property and value.

*

A value of any type other than a function that will be set as the DEFAULT-ATTR attribute's value.

map.each( callback(item, propName ) )

each iterates through the Map, calling a function for each property value and key.

  1. callback {function(item, propName)}: the function to call for each property The value and key of each property will be passed as the first and second arguments, respectively, to the callback. If the callback returns false, the loop will stop.
  • returns {can-map}: this Map, for chaining
map.removeAttr(attrName)
  1. attrName {String}: the name of the property to remove
  • returns {*}: the value of the property that was removed
map.serialize()

Get the serialized Object form of the map. Serialized data is typically used to send back to a server.

o.serialize() //-> { name: 'Justin' }

Serialize currently returns the same data as [can.Map.prototype.attrs]. However, in future versions, serialize will be able to return serialized data similar to [can.Model]. The following will work:

new Map({time: new Date()})
    .serialize() //-> { time: 1319666613663 }
  • returns {Object}: a JavaScript Object that can be serialized with JSON.stringify or other methods.
map.unbind(eventType[, handler])
  1. eventType {String}: the type of event to unbind, exactly as passed to bind
  2. handler {function}: the handler to unbind
var map = new Map({ a: 1 });

function log(){
	console.log("val", map.attr("a");
}

map.bind("change", log);

map.attr("a", 2);

// Bind callback called.
map.unbind("change", log);
Map.keys(map)
var people = new Map({
		a: 'Alice',
		b: 'Bob',
		e: 'Eve'
});

Map.keys(people); // ['a', 'b', 'e']
  1. map {can-map}: the Map to get the keys from
  • returns {Array}: array An array containing the keys from map.

Contributing

Making a Build

To make a build of the distributables into dist/ in the cloned repository run

npm install
node build

Running the tests

Tests can run in the browser by opening a webserver and visiting the test.html page. Automated tests that run the tests from the command line in Firefox can be run with

npm test

Keywords

FAQs

Package last updated on 28 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc