UNPKG

foam-framework

Version:
68 lines (60 loc) 1.65 kB
/** * @license * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ CLASS({ name: 'StorageDAO', package: 'foam.core.dao', extends: 'MDAO', properties: [ { name: 'name', label: 'Store Name', type: 'String', defaultValueFn: function() { debugger; return this.model.id; } } ], methods: { init: function() { this.SUPER(); var objs = localStorage.getItem(this.name); if ( objs ) JSONUtil.parse(this.Y, objs).select(this); this.addRawIndex({ execute: function() {}, bulkLoad: function() {}, toString: function() { return "StorageDAO Update"; }, plan: function() { return { cost: Number.MAX_VALUE }; }, put: this.updated, remove: this.updated }); } }, listeners: [ { name: 'updated', isMerged: 100, code: function() { this.select()(function(a) { localStorage.setItem(this.name, JSONUtil.compact.where(NOT_TRANSIENT).stringify(a)); }.bind(this)); } } ] });