Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
],
"devDependencies": {
"web-component-tester": "^4.0.0",
"polymer": "^1.8.0"
"polymer": "^2.2.0"
},
"resolutions": {
"webcomponentsjs": "^v1.0.2"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"gulp-process-inline": "^0.1.1",
"gulp-size": "^2.0.0",
"run-sequence": "^1.1.5",
"simpla": "^3.0.1",
"web-component-tester": "^5.0.0",
"yargs": "^7.1.0"
}
Expand Down
2 changes: 1 addition & 1 deletion simpla-element-behavior.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<script>"use strict";function _defineProperty(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}var _extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var i in a)Object.prototype.hasOwnProperty.call(a,i)&&(e[i]=a[i])}return e},DEFAULT_CONFIG={getCallback:"_updateFromSimpla",setCallback:"_updateSimplaBuffer"},ERRORS={NO_SIMPLA:"Cannot find Simpla, ensure it is included before this component"};window.SimplaBehaviors=window.SimplaBehaviors||{},SimplaBehaviors.Element=function(e){var t=_extends({},DEFAULT_CONFIG,e),a=t.type,i=t.getCallback,r=t.setCallback,n=t.dataProperties,o=function(e){return"_syncedPropertiesObserver("+e+".*)"};return{properties:{path:{type:String,observer:"_initPathIfReady"},editable:{type:Boolean,observer:"_disableEditableIfReadonly",notify:!0},readonly:{type:Boolean,observer:"_updateReadonly"},loaded:{type:Boolean,readOnly:!0,notify:!0,value:!1},__simplaObservers:{type:Object,value:function(){return{}}}},observers:n.map(o),created:function(){if(!window.Simpla)throw new Error(ERRORS.NO_SIMPLA)},attached:function(){this._attached=!0,this.editable=!this.readonly&&(this.editable||Simpla.getState("editable")),this._observeSimplaEditable(),this._initPathIfReady(this.path)},detached:function(){var e=this;Object.keys(this.__simplaObservers).forEach(function(t){e.__simplaObservers[t].unobserve()}),this.__simplaObservers={}},_initPathIfReady:function(e){this._attached&&void 0!==e&&this._initSimplaPath(e)},_updateReadonly:function(e){this.editable=!e&&Simpla.getState("editable")},_disableEditableIfReadonly:function(e){this.readonly&&e&&(this.editable=!1)},_initSimplaPath:function(e){var t=this;this._setLoaded(!1),Simpla.get(e).then(function(a){var i=!(a&&a.data),r=t.path!==e,n=Simpla.getState("buffer"),o=n&&n[e]&&!n[e].modified;r||(i&&o?t._protectedSetCallback():t._protectedGetCallback(a),t._setLoaded(!0))}),this._observeSimplaBuffer(e)},_observeSimplaBuffer:function(e){var t=this,a=this.__simplaObservers;e&&(a.buffer&&a.buffer.unobserve(),a.buffer=Simpla.observe(e,function(e){e&&e.data&&t._protectedGetCallback(e)}))},_updateSimplaBuffer:function(){var e=this;return n.reduce(function(t,a){return _extends(t,_defineProperty({},a,e[a]))},{})},_updateFromSimpla:function(e){_extends(this,e.data)},_protectedGetCallback:function(e){this.__loadingFromSimpla=!0,this[i](e),this.__loadingFromSimpla=!1},_protectedSetCallback:function(){if(!this.__loadingFromSimpla&&this._attached&&this.path){var e=this[r]();void 0===e&&null!==e||Simpla.set(this.path,{type:a,data:e})}},_syncedPropertiesObserver:function(){this.loaded&&this._protectedSetCallback()},_observeSimplaEditable:function(){var e=this,t=this.__simplaObservers;t.editable&&t.editable.unobserve(),t.editable=Simpla.observeState("editable",function(t){e.readonly||(e.editable=t)})}}}</script>
<script>"use strict";function _defineProperty(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function changed(e,t,i){e.dispatchEvent(new CustomEvent(t+"-changed",{detail:{value:i}}))}var _extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n])}return e},_createClass=function(){function e(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),t}}(),_get=function e(t,i,n){null===t&&(t=Function.prototype);var r=Object.getOwnPropertyDescriptor(t,i);if(void 0===r){var a=Object.getPrototypeOf(t);return null===a?void 0:e(a,i,n)}if("value"in r)return r.value;var o=r.get;if(void 0!==o)return o.call(n)},ERRORS={NO_SIMPLA:"Cannot find Simpla, ensure it is included before this component"};window.SimplaElement=function(e){return function(e){function t(){_classCallCheck(this,t);var e=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));if(!window.Simpla)throw new Error(NO_SIMPLA);return e._loaded=!1,e.__simplaObservers={},e.__triggerBufferSync=function(){e.loaded&&e._protectedSetCallback()},e}return _inherits(t,e),_createClass(t,[{key:"attributeChangedCallback",value:function(e,t,i){"path"===e?this.path=i:this[e]=null!==i}},{key:"connectedCallback",value:function(){var e=this,i=this.constructor.simplaConfig.events;_get(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"connectedCallback",this)&&_get(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"connectedCallback",this).call(this),i.forEach(function(t){return e.addEventListener(t,e.__triggerBufferSync)}),this.editable=!this.readonly&&(this.editable||Simpla.getState("editable")),this._observeSimplaEditable(),this._initPathIfReady(this.path)}},{key:"disconnectedCallback",value:function(){var e=this,i=this.constructor.simplaConfig.events;_get(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"disconnectedCallback",this)&&_get(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"disconnectedCallback",this).call(this),i.forEach(function(t){return e.removeEventListener(t,e.__triggerBufferSync)}),Object.keys(this.__simplaObservers).forEach(function(t){e.__simplaObservers[t].unobserve()}),this.__simplaObservers={}}},{key:"_initPathIfReady",value:function(e){this.isConnected&&void 0!==e&&this._initSimplaPath(e)}},{key:"_initSimplaPath",value:function(e){var t=this;this._loaded=!1,Simpla.get(e).then(function(i){var n=!(i&&i.data),r=t.path!==e,a=Simpla.getState("buffer"),o=a&&a[e]&&!a[e].modified;r||(n&&o?t._protectedSetCallback():t._protectedGetCallback(i),t._loaded=!0)}),this._observeSimplaBuffer(e)}},{key:"_observeSimplaBuffer",value:function(e){var t=this,i=this.__simplaObservers;e&&(i.buffer&&i.buffer.unobserve(),i.buffer=Simpla.observe(e,function(e){e&&e.data&&t._protectedGetCallback(e)}))}},{key:"updateSimplaBuffer",value:function(){var e=this;return this.constructor.simplaConfig.dataProperties.reduce(function(t,i){return _extends(t,_defineProperty({},i,e[i]))},{})}},{key:"updateFromSimpla",value:function(e){_extends(this,e.data)}},{key:"_protectedGetCallback",value:function(e){this.__loadingFromSimpla=!0,this.updateFromSimpla(e),this.__loadingFromSimpla=!1}},{key:"_protectedSetCallback",value:function(){if(!this.__loadingFromSimpla&&this.isConnected&&this.path){var e=this.updateSimplaBuffer(),t=this.constructor.simplaConfig.type;void 0===e&&null!==e||Simpla.set(this.path,{type:t,data:e})}}},{key:"_observeSimplaEditable",value:function(){var e=this,t=this.__simplaObservers;t.editable&&t.editable.unobserve(),t.editable=Simpla.observeState("editable",function(t){e.editable=t})}},{key:"path",get:function(){return this.__path},set:function(e){var t=this.__path;this.__path=e,e!==t&&this._initPathIfReady(e)}},{key:"editable",get:function(){return this.__editable},set:function(e){var t=this.__editable;this.readonly||(this.__editable=e,e!==t&&changed(this,"editable",e))}},{key:"readonly",get:function(){return this.__readonly},set:function(e){var t=this.__readonly;this.__readonly=!1,e||!0!==t?e&&(this.editable=!1):this.editable=Simpla.getState("editable"),this.__readonly=e}},{key:"loaded",get:function(){return this.__loaded}},{key:"_loaded",set:function(e){var t=this.__loaded;this.__loaded=e,e!==t&&changed(this,"loaded",e)}}],[{key:"observedAttributes",get:function(){return["path","editable","readonly","loaded"]}}]),t}(e)}</script>
Loading