{"_id":"@atlassian/backbone-brace","_rev":"60-848cb1d5ef75966d7b61f1dbad742ec6","name":"@atlassian/backbone-brace","dist-tags":{"latest":"1.3.0"},"versions":{"1.3.0":{"name":"@atlassian/backbone-brace","version":"1.3.0","keywords":["backbone","brace","backbone.brace"],"author":{"name":"Atlassian Pty Ltd."},"license":"Apache-2.0","_id":"@atlassian/backbone-brace@1.3.0","maintainers":[{"name":"atlassian_fabric_elements","email":"jhoarau+elements@atlassian.com"},{"name":"atlassian-aui","email":"aui-team@atlassian.com"},{"name":"cdarroch","email":"cdarroch@atlassian.com"},{"name":"cwhittington","email":"cwhittington@atlassian.com"},{"name":"dboyd","email":"dboyd@atlassian.com"},{"name":"dmorrow","email":"dmorrow@atlassian.com"},{"name":"dwalker","email":"dwalker@atlassian.com"},{"name":"jameslnewell","email":"james@digitaledgeit.com.au"},{"name":"jhoarau","email":"jhoarau@atlassian.com"},{"name":"jvdl","email":"jvanderloo@atlassian.com"},{"name":"macku","email":"npm@maciejadamczak.net"},{"name":"mdejongh","email":"mdejongh@atlassian.com"},{"name":"mstaas","email":"mstaas@atlassian.com"},{"name":"mszczepanski","email":"mszczepanski@atlassian.com"},{"name":"raqystyle","email":"raqy.style@gmail.com"},{"name":"shnooshnoo","email":"arturufa88@gmail.com"}],"dist":{"shasum":"7ae6b2b8c8c38a3a3dca9c899efa52527680d9df","tarball":"https://registry.npmjs.org/@atlassian/backbone-brace/-/backbone-brace-1.3.0.tgz","fileCount":20,"integrity":"sha512-13/m/TcE+ef+WIvehnQY1KsihupPM+JuFNzHry2iKQvx9DLxWmBCIiD6PHXBmPJp2KXeYPeP6lKaM/DsvQh+LA==","signatures":[{"sig":"MEYCIQC9knKMYfXk60HLsT2yTvGOYqgr1jTWpF0xDKgXrj9SzgIhAIBWroS3kW/ePnAwKC/kkhqF4+TcyuzL7MA/x2NkqueU","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":240421,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh12BHCRA9TVsSAnZWagAAHwgQAJHgM1NbMFHNFoq7bWJP\no3fBUT+9A9A8Jdop/AKBdaNigy1dKweN8TVGTJIiyZMnmv8OkxkaJnBmF59Z\nHwAdhr1F5ojEyLTxTAqNQQOcZFcFx/g+NkJmEaY4G4eSgmqyoNIi+zZ97bQZ\nrsr+BEfF+wrvYR/IbfdeZbSL3ezY6+91jpvrztEwiEdxiHqhxBCG9MwfSi4D\n9RGsj5gpaB3x1gQfyQs1LsxRUNQcqp8ZvtQq0wgGHNCl75BIVQm9tv7Bxyn7\n33A6XmvgHXXr4PhAWlSvLMCC3n67fr5JRTZ8g6z7Zuj6fXD6UqfnErH5LY6k\njokLEn+qkjcOcBKJ+vwW8RmR1Vjbik0rupkRBbZeI85f/eIz77nAiVPiSHeP\nonmMbKQd5m6D1+E03cYFcGBKo6gj8gI/bUiIfqm0ld+ywALdcSGO1o5SGr2F\njo6ZMc9iq5EuJ/g5Uc8PBpGblLkmRLx5AqI+qgh2wSB2tcsYkOv/WpETJsjF\ngf9+HP3KCjBmqo91huzMdctyPsh1KXAQWcCULLqDgE07AVEn2zfxR726SDSK\nJL7H8ifLZZ0DvB3EJ5Rty9DfWWdab67kxCeKaZGiDTLnbWynF6+PeDVI+G2t\n9exiNrBUs0eeGr0EWrTG38s9LQqwVssouKGaPstf4O8klHrY4aU2z2C97LfB\n6BHr\r\n=H8Z8\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/backbone.brace.js","gitHead":"5ec218936c7c67f759241782a11cab38c8a419c4","scripts":{"test":"grunt connect qunit"},"_npmUser":{"name":"macku","email":"npm@maciejadamczak.net"},"repository":{"url":"ssh://git@stash.atlassian.com:7997/fe/backbone-brace.git","type":"git"},"_npmVersion":"6.1.0","description":"Brace is an extension to [Backbone](http://backbonejs.org) that adds mixins and self-documenting attributes & events.","directories":{"doc":"docs","test":"test"},"_nodeVersion":"8.9.4","_hasShrinkwrap":false,"devDependencies":{"docco":"~0.6.2","grunt":"~0.4.1","grunt-contrib-qunit":"~0.2.1","grunt-contrib-watch":"~0.3.1","grunt-contrib-concat":"~0.3.0","grunt-contrib-jshint":"~0.4.3","grunt-contrib-uglify":"~0.2.0","grunt-contrib-connect":"~0.3.0"},"_npmOperationalInternal":{"tmp":"tmp/backbone-brace_1.3.0_1529573408450_0.45577607640910545","host":"s3://npm-registry-packages"}}},"time":{"created":"2018-06-21T09:30:08.450Z","modified":"2025-01-29T05:31:28.886Z","1.3.0":"2018-06-21T09:30:08.637Z"},"author":{"name":"Atlassian Pty Ltd."},"license":"Apache-2.0","keywords":["backbone","brace","backbone.brace"],"repository":{"url":"ssh://git@stash.atlassian.com:7997/fe/backbone-brace.git","type":"git"},"description":"Brace is an extension to [Backbone](http://backbonejs.org) that adds mixins and self-documenting attributes & events.","maintainers":[{"email":"eng-development-tooling-secrets-and-artifacts@atlassian.com","name":"atlassianartifactteam"}],"readme":"# Backbone.Brace\n\nBrace is an extension to [Backbone](http://backbonejs.org) that adds mixins and self-documenting attributes & events.\n\n## Self-documenting attributes and events\n\nBrace allows:\n\n- \"namedEvents\" on Models, Collections, Views and Routers, which is a collection of exposed events\n- \"namedAttributes\" on Models, which is a collection of exposed attributes - ie a model schema\n\nBoth namedEvents and namedAttributes are arrays of strings. namedAttributes can also be an object.\n\n    :::javascript\n    var Person = Brace.Model.extend({\n        namedAttributes: [\"name\"],\n        namedEvents: [\"sleep\"]\n    });\n\nFor each attribute in namedAttributes, get[Attribute] and set[Attribute] methods are generated:\n\n    :::javascript\n    var person = new Person();\n    person.setName(\"Tim\");\n    person.getName() // Returns \"Tim\"\n\nBackbone models' get() and set() validate attributes:\n\n    :::javascript\n    person.get(\"name\"); // ok\n    person.set(\"name\", \"Timmy\"); // ok\n    person.set({\n        name: \"Timothy\"\n    }); // ok\n    \n    person.get(\"lost\"); // throws exception\n    person.set(\"lost\", \"frequently\"); // throws exception\n    person.set({\n        lost: \"frequently\"\n    }); // throws exception\n\nThe types of your namedAttributes are validated and coerced when namedAttributes is an object:\n    \n    :::javascript\n    var People = Brace.Collection.extend();\n    var Person = Brace.Model.extend({\n        namedAttributes: {\n            name : \"string\", // validate primitives with typeof\n            otherNames : [ \"string\" ], // validate typed array-likes\n            birthDate : Date, // validate arbitrary ctors with instanceof,\n                              // calls `new ctor(rawValue)` if necessary\n            children : People, // validate Backbone.Collections,\n                               // coerces arrays and contained models if necessary\n            attributes : Array, // validate untyped array-likes\n            metadata : null || undefined || false // skip validation completely\n        }\n    });\n    People.model = Person;\n\n    var person = new Person({ name : 'Enigma' }); // ok\n    person.set('name', null); // ok\n    person.set('name', 'Nazim'); // ok\n    person.set('name', 4); // throws exception\n\n    person.set('otherNames', [ 'Ahmed' ]); // ok\n    person.set('otherNames', [ 1, 4 ]); // throws exception\n\n    person.set('attributes', [ 'one', 2, {} ]); // ok\n    person.set('attributes', 'The Dude'); // throws exception\n\n    person.set('birthDate', 'Mar 12 1960'); // ok\n    person.get('birthDate').toString(); // \"Sat Mar 12 1960 00:00:00 GMT+1100 (AUS Eastern Daylight Time)\"\n\n    person.set('children', [ { name : 'Adam' }, { name : 'Mariam' }, { name : 'Sarah' } ]); // ok\n    person.get('children'); // returns People instance containing three Person models.\n\n\nFor each event in namedEvents, on[Event] and trigger[Event] methods are generated:\n    \n    :::javascript\n    person.onSleep(function(dream) { console.log(\"Dreaming about \" + dream); } );\n    person.triggerSleep(\"Unicorns\");\n\n\n## Mixins\n\nBrace allows a \"mixins\" property on models, views, collections and routers:\n\n    :::javascript\n    var Loggable = {\n        log: function(msg) {\n            console.log(msg);\n        }\n    };\n    \n    var PersonView = Brace.View.extend({\n        mixins: [Loggable],\n        \n        initialize: function() {\n            this.log(\"Initialized\");\n        }\n    });\n\n\n## Mixins with Backbone\n\nnamedAttributes and namedEvents in mixins are respected:\n\n    :::javascript\n    var Selectable = {\n        namedAttributes: [\"selected\"],\n        namedEvents: [\"select\"],\n\n        initialize: function() {\n            this.on(\"change:selected\", _.bind(function(model, selected) {\n                if (selected) {\n                    this.triggerSelect();\n                }\n            }, this));\n        }\n    };\n\n    var Person = Brace.Model.extend({\n        mixins: [Selectable]\n    });\n    \n    var person = new Person();\n\n    person.onSelect(function() { console.log(\"Person was selected\"); });\n    person.setSelected(true);\n    person.getSelected();\n    person.triggerSelect();\n\nAdditionally, Brace composes \n\n- initialize() on all objects, and\n- defaults and validate() on models\n\nAll other name clashes between mixins fail violently and forcefully *at class declaration time* (not at instance construction time).\n\n    :::javascript\n    var Runnable = {\n        run: function() {}\n    };\n    \n    var RunModel = Brace.Model.extend({\n        mixins: [Runnable],\n        run: function() {}\n    }); // throws \"Mixin error: class already has property 'run' defined\"\n    \n    \n    \n","readmeFilename":"README.md"}