{"action":"created","issue":{"url":"https://api.github.com/repos/teijo/jquery-bracket/issues/36","labels_url":"https://api.github.com/repos/teijo/jquery-bracket/issues/36/labels{/name}","comments_url":"https://api.github.com/repos/teijo/jquery-bracket/issues/36/comments","events_url":"https://api.github.com/repos/teijo/jquery-bracket/issues/36/events","html_url":"https://github.com/teijo/jquery-bracket/issues/36","id":68588620,"number":36,"title":"Double Elimination save option","user":{"login":"thecodeassassin","id":939775,"avatar_url":"https://avatars.githubusercontent.com/u/939775?v=3","gravatar_id":"","url":"https://api.github.com/users/thecodeassassin","html_url":"https://github.com/thecodeassassin","followers_url":"https://api.github.com/users/thecodeassassin/followers","following_url":"https://api.github.com/users/thecodeassassin/following{/other_user}","gists_url":"https://api.github.com/users/thecodeassassin/gists{/gist_id}","starred_url":"https://api.github.com/users/thecodeassassin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thecodeassassin/subscriptions","organizations_url":"https://api.github.com/users/thecodeassassin/orgs","repos_url":"https://api.github.com/users/thecodeassassin/repos","events_url":"https://api.github.com/users/thecodeassassin/events{/privacy}","received_events_url":"https://api.github.com/users/thecodeassassin/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-04-15T06:16:44Z","updated_at":"2015-05-10T13:53:19Z","closed_at":"2015-05-10T13:53:19Z","body":"Hey there,\r\n\r\nI'm using the saveFn function to save results to the database. The problem i'm having is that this doesn't work with Double Elimination since detecting whether or not it's double elimination depends on the data itself. Is there a flag i can use to force it to double elimination?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/teijo/jquery-bracket/issues/comments/100644870","html_url":"https://github.com/teijo/jquery-bracket/issues/36#issuecomment-100644870","issue_url":"https://api.github.com/repos/teijo/jquery-bracket/issues/36","id":100644870,"user":{"login":"teijo","id":977817,"avatar_url":"https://avatars.githubusercontent.com/u/977817?v=3","gravatar_id":"","url":"https://api.github.com/users/teijo","html_url":"https://github.com/teijo","followers_url":"https://api.github.com/users/teijo/followers","following_url":"https://api.github.com/users/teijo/following{/other_user}","gists_url":"https://api.github.com/users/teijo/gists{/gist_id}","starred_url":"https://api.github.com/users/teijo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teijo/subscriptions","organizations_url":"https://api.github.com/users/teijo/orgs","repos_url":"https://api.github.com/users/teijo/repos","events_url":"https://api.github.com/users/teijo/events{/privacy}","received_events_url":"https://api.github.com/users/teijo/received_events","type":"User","site_admin":false},"created_at":"2015-05-10T13:53:19Z","updated_at":"2015-05-10T13:53:19Z","body":"**tl;dr** Bracket type still depends on initialization data, and it should. Unfortunately the double elimination initialization data is ugly if backwards compatibility is concerned: `[[[[]]], [], []]`.\r\n\r\nI went through the input handling and found what the problem is. From https://github.com/teijo/jquery-bracket/blob/3a4210cb8bca6b44f2789d12197c5f5815491a42/src/jquery.bracket.ts#L1103\r\n\r\n```javascript\r\n    var r = data.results\r\n\r\n    /* wrap data to into necessary arrays */\r\n    r = wrap(r, 4 - depth(r))\r\n    data.results = r\r\n\r\n    var isSingleElimination = (r.length <= 1)\r\n```\r\n\r\nThe results data is normalized with the `wrap()`. It nests arrays until they are 4 deep, that is:\r\n 1. list of brackets\r\n 2. list of rounds in bracket\r\n 3. list of matches in round\r\n 4. a match\r\n\r\nIf nesting is missing, it will wrap the data until 4 levels exist, therefore giving just `[1, 2]` as result would convert it as result of first match of first round in single bracket -> `[[[[1, 2]]]]`.\r\n\r\nThe bracket type is determined by the number of bracket lists (top level) in the normalized result input. 1 for single bracket, greater than 1 for double elimination. Example above in double elimination would be `[[[[1, 2]]], [], []]`\r\n\r\nClosing this issue as the data can define the bracket type. As the bracket edit mode output by `saveFn` will output normalized data which, when read in init, will result into correct behaviour, no additional option for double elimination output is needed.\r\n\r\nImprovement to the API would be to discard the normalization and enforce exact input format from the beginning. However, that will not be backwards compatible and therefore not desirable at this point."}}