-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from canjs/major
Merge major branch for 6.0 release
- Loading branch information
Showing
23 changed files
with
874 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
@function can-stache-element/lifecycle-methods.bindings bindings | ||
@parent can-stache-element/lifecycle-methods 6 | ||
|
||
Programmatically instantiate a component | ||
|
||
@signature `element.bindings([props])` | ||
|
||
Create bindings between an element's properties and parent observables. This is useful when you: | ||
|
||
- have complex logic for switching between different components (e.g. routing) | ||
|
||
The following defines `HomePage` and `MyApp` components that sets up bindings between them: | ||
|
||
```js | ||
class HomePage extends StacheElement { | ||
static props = { | ||
pageId: Number | ||
} | ||
} | ||
|
||
class MyApp extends StacheElement { | ||
static view = `{{{component}}}` | ||
|
||
static props = { | ||
componentName: String, | ||
pageId: Number, | ||
|
||
component: { | ||
get() { | ||
if(componentName === "home") { | ||
return new HomePage().bindings({ | ||
pageId: value.from(this, "pageId") | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
@param {Object} [props] Child properties to bind to. | ||
@return {can-stache-element} The StacheElement instance. | ||
|
||
@body | ||
|
||
## Use | ||
|
||
Pass an object of properties to bind to the element. For example: | ||
|
||
```js | ||
import {StacheElement, ObservableObject, value} from "can"; | ||
|
||
const appVM = new ObservableObject({ | ||
association: "friend" | ||
}); | ||
|
||
class MyGreeting extends StacheElement { | ||
static view = `{{greeting}} {{subject}}` | ||
|
||
static props = { | ||
greeting: String, | ||
subject: String | ||
} | ||
} | ||
customElements.define("my-greeting", MyGreeting); | ||
|
||
const myGreetingInstance = new MyGreeting().bindings({ | ||
greeting: "Hello", | ||
subject: value.bind(appVM, "association") | ||
}).render(); | ||
|
||
console.log( myGreetingInstance ); | ||
// logs <my-greeting>Hello friend</my-greeting> | ||
|
||
console.log( myGreetingInstance.subject ); | ||
// logs "friend" | ||
``` | ||
@codepen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "can-stache-element", | ||
"description": "Create custom elements with can-stache, can-observable-object, and JavaScript classes", | ||
"version": "0.8.1", | ||
"version": "1.0.0-pre.16", | ||
"author": { | ||
"name": "Bitovi", | ||
"email": "[email protected]", | ||
|
@@ -12,26 +12,29 @@ | |
"url": "https://github.com/canjs/can-stache-element/issues" | ||
}, | ||
"dependencies": { | ||
"can-bind": "^1.4.3", | ||
"can-child-nodes": "^1.2.1", | ||
"can-bind": "^1.5.0", | ||
"can-define-lazy-value": "^1.1.0", | ||
"can-dom-mutate": "^2.0.3", | ||
"can-log": "^1.0.2", | ||
"can-observable-mixin": "<2.0.0", | ||
"can-observable-mixin": "^1.0.0-pre.11", | ||
"can-queues": "^1.3.0", | ||
"can-simple-observable": "^2.4.2", | ||
"can-stache": "^4.0.0", | ||
"can-stache-bindings": "^4.0.0", | ||
"can-symbol": "^1.6.4", | ||
"can-view-nodelist": "^4.3.4" | ||
"can-stache": "^5.0.0-pre.2", | ||
"can-stache-bindings": "^5.0.0-pre.6", | ||
"can-symbol": "^1.6.4" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.4.4", | ||
"@babel/core": "^7.4.5", | ||
"@babel/preset-env": "^7.4.5", | ||
"@webcomponents/custom-elements": "^1.2.4", | ||
"can-observable-bindings": "^1.1.0", | ||
"can-reflect": "^1.17.11", | ||
"can-reflect-dependencies": "^1.1.2", | ||
"can-test-helpers": "^1.1.4", | ||
"can-type": "^0.2.0", | ||
"can-type": "^1.0.0-pre.2", | ||
"can-value": "^1.1.1", | ||
"can-view-callbacks": "^4.4.0", | ||
"can-view-callbacks": "^5.0.0-pre.1", | ||
"can-view-scope": "^4.13.1", | ||
"detect-cyclic-packages": "^1.1.0", | ||
"fixpack": "^2.3.1", | ||
|
@@ -53,13 +56,14 @@ | |
"url": "git://github.com/canjs/can-stache-element.git" | ||
}, | ||
"scripts": { | ||
"ci": "npm run test && node test/test-saucelabs.js && npm run compile-to-es5", | ||
"ci": "npm run test && node test/test-saucelabs.js", | ||
"compile-to-es5": "babel src --out-dir dist", | ||
"detect-cycle": "detect-cyclic-packages", | ||
"http-server": "http-server -p 3000 --silent", | ||
"jshint": "jshint src/*.js test/*.js --config", | ||
"lint": "fixpack && npm run jshint", | ||
"postversion": "git push --follow-tags", | ||
"prepublishOnly": "npm run compile-to-es5", | ||
"preversion": "npm test", | ||
"test": "npm run detect-cycle && npm run lint && npm run testee", | ||
"testee": "testee test/test.html --browsers firefox" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.