(key, value, callback)
| 1978 | } |
| 1979 | |
| 1980 | function setItem(key, value, callback) { |
| 1981 | var self = this; |
| 1982 | |
| 1983 | key = normalizeKey(key); |
| 1984 | |
| 1985 | var promise = new Promise$1(function (resolve, reject) { |
| 1986 | var dbInfo; |
| 1987 | self.ready().then(function () { |
| 1988 | dbInfo = self._dbInfo; |
| 1989 | if (toString.call(value) === '[object Blob]') { |
| 1990 | return _checkBlobSupport(dbInfo.db).then(function (blobSupport) { |
| 1991 | if (blobSupport) { |
| 1992 | return value; |
| 1993 | } |
| 1994 | return _encodeBlob(value); |
| 1995 | }); |
| 1996 | } |
| 1997 | return value; |
| 1998 | }).then(function (value) { |
| 1999 | createTransaction(self._dbInfo, READ_WRITE, function (err, transaction) { |
| 2000 | if (err) { |
| 2001 | return reject(err); |
| 2002 | } |
| 2003 | |
| 2004 | try { |
| 2005 | var store = transaction.objectStore(self._dbInfo.storeName); |
| 2006 | |
| 2007 | // The reason we don't _save_ null is because IE 10 does |
| 2008 | // not support saving the `null` type in IndexedDB. How |
| 2009 | // ironic, given the bug below! |
| 2010 | // See: https://github.com/mozilla/localForage/issues/161 |
| 2011 | if (value === null) { |
| 2012 | value = undefined; |
| 2013 | } |
| 2014 | |
| 2015 | var req = store.put(value, key); |
| 2016 | |
| 2017 | transaction.oncomplete = function () { |
| 2018 | // Cast to undefined so the value passed to |
| 2019 | // callback/promise is the same as what one would get out |
| 2020 | // of `getItem()` later. This leads to some weirdness |
| 2021 | // (setItem('foo', undefined) will return `null`), but |
| 2022 | // it's not my fault localStorage is our baseline and that |
| 2023 | // it's weird. |
| 2024 | if (value === undefined) { |
| 2025 | value = null; |
| 2026 | } |
| 2027 | |
| 2028 | resolve(value); |
| 2029 | }; |
| 2030 | transaction.onabort = transaction.onerror = function () { |
| 2031 | var err = req.error ? req.error : req.transaction.error; |
| 2032 | reject(err); |
| 2033 | }; |
| 2034 | } catch (e) { |
| 2035 | reject(e); |
| 2036 | } |
| 2037 | }); |
nothing calls this directly
no test coverage detected