Giter VIP home page Giter VIP logo

can-observable-object's Introduction

can-observable-object

Build Status Greenkeeper badge

The ObservableObject

Usage

ES6 use

With StealJS, you can import this module directly in a template that is autorendered:

import plugin from 'can-observable-object';

CommonJS use

Use require to load can-observable-object and everything else needed to create a template that uses can-observable-object:

var plugin = require("can-observable-object");

Standalone use

Load the global version of the plugin:

<script src='./node_modules/can-observable-object/dist/global/can-observable-object.js'></script>

can-observable-object's People

Contributors

chasenlehara avatar cherifgsoul avatar greenkeeper[bot] avatar m-mujica avatar matthewp avatar phillipskevin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

stealify leoj3n

can-observable-object's Issues

Don't hard-overwrite can.meta and other thoughts

define.setup does the following:

Object.defineProperty(this,"constructor", {value: this.constructor, enumerable: false, writable: false});
Object.defineProperty(this,canMetaSymbol, {value: Object.create(null), enumerable: false, writable: false});

This makes it so if a can.meta is already established, this gets overwritten every time .initialize() is called ...

This creates problems for can-stache-define-element because:

  • elements exist before they are initialized
  • elements should be able to be re-initialized when disconnected

I think we might want to separate define.setup into "initialize" and "finalizeInstance".

finalizeInstance should prepare the instance for anything that needs to exist for a working instance. It's similar to finalizeClass. It needs to be called only once on the instance for "all time".

initialize() should be able to be called multiple times without breaking what has been done in finalizeClass.

ObservableObject.prototype.set throws an error #83

SAME AS canjs/can-observable-array#83

With the changes to make class fields observable, setting expando properties using .set is now broken. Here is an example:

class Foo extends ObservableObject{}
const foo = new Foo();
foo.set("action", 10);

This is the error thrown:

Uncaught TypeError: Cannot read property 'action' of undefined
    at Object.get MyMap{}.action [as get] (define.js:809)
    at Object.defineProperty (can-observable-object.js:29)
    at Function.defineProperty (<anonymous>)
    at Object_defineNamedPrototypeProperty (define.js:81)
    at Function.define.property (define.js:410)
    at Object.define.expando [as defineExpando] (define.js:1167)
    at Proxy.setKeyValue (mixin-mapprops.js:57)
    at Proxy.set (mixin-mapprops.js:108)
    at canRoute._onStartComplete (route-observable-test.js:229)
    at eval (can-route.js:84)

Documentation

This is a meta issue for all of the documentation needed. Much of this comes from the design doc.

  • static define = {}
  • getters/setters on the prototype
  • DefineObject
  • DefineArray
  • static items = Todo
  • type.maybe()
  • type.convert()
  • type.check()
  • type.maybeConvert()
  • type.Any
  • static propertyDefaults = {}
  • new ExtendedDefineClass({propNotDefined: "value"})
  • static seal = false

PropDefinitions

  • age: 36 - default
  • age: Number primitive constructor
  • age: NumberType constructor
  • age: type.convert(Number) using can-type
  • age: function() { } Used as the default value
  • age: {} propDefinition

PropDefinitions object

  • type
  • default: Primitive | Function | Object
  • get default() { }
  • get() { }
  • set( [newVal] [,lastSet] ){}
  • async( [resolve] ){}
  • value( {resolve, listenTo, stopListening, lastSet}){}
  • required: Boolean=false
  • enumerable: Boolean
  • serialize(value): Any

An in-range update of can-observable-mixin is breaking the build 🚨

The dependency can-observable-mixin was updated from 1.0.0-pre.11 to 1.0.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

can-observable-mixin is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details

Commits

The new version differs by 10 commits.

  • 83be9f4 1.0.0
  • 56446e2 Merge pull request #139 from canjs/nonpre
  • 21bf458 Upgrade to non-pre package versions
  • e1018d9 Merge pull request #138 from canjs/major
  • 071936f Merge branch 'master' into major
  • 71d5aac 0.4.6
  • 1f9fec2 Merge pull request #130 from canjs/no-proxy
  • 90a5532 - Avoids use of ES Proxies when not supported.
  • c69632a Merge pull request #124 from canjs/greenkeeper/can-reflect-tests-1.0.0
  • dec953b chore(package): update can-reflect-tests to version 1.0.0

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Do not observe symbols.

I think if someone tries:

var s = new Symbol();

o = new DefineObject();

ObservationRecorder.start();
o[s]
var records = ObservationRecorder.stop();

records will include something for the symbol. This creates unnecessary bindings. We should never listen to a symbol property.

Rename to can-observable-object

  • create a can-define-object-legacy branch
  • update readme with a deprecation notice and link to can-observable-object
  • publish a patch to NPM
  • rename repository and package name to can-observable-object
  • Rename export to ObservableObject
  • use can-define-mixin that supports props
  • update documentation to show ObservableObject and props everywhere
  • publish can-observable-object
  • update canjs#master to use new package and export both DefineObject and ObservableObject
  • npm deprecate can-define-object

setKeyValue dispatches multiple events

Using canReflect.setKeyValue dispatches more than one event:

defineProperty(target, prop, descriptor) {

Using setKeyValue will have a descriptor with getter and setter and this case should be handled in the returned proxy.

Another issue to fix is to add the instance to the observable instances in observable-mixin:
https://github.com/canjs/can-observable-mixin/blob/dea26780f37fc75aeba6ea9d8409f0701e90d157/src/mixin-proxy.js#L80

How should we document getters?

These all work:

class Obj extends DefineObject {
    static define = {
        name: { default: "Kevin" },
        get excitedName() {
            return this.name + "!!!";
        },
        lowerCaseName: {
            get() {
                return this.name.toLowerCase()
            }
        }
    };
    get upperCaseName() {
        return this.name.toUpperCase()
    }
  }

Should we document them all?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.