<commit_before>package polymer

import (
	"github.com/gopherjs/gopherjs/js"
	"reflect"
)

var typeOfPtrBindProto = reflect.TypeOf(&BindProto{})

type BindInterface interface {
	Notify(path string)
	data() *BindProto
}

type BindProto struct {
	this *js.Object
	Element
}

func (p *BindProto) data() *BindProto { return p }
func (p *BindProto) Notify(path string) {
	lookupProto(p.data().this).data().Notify("model." + path)
}

type AutoBindGoTemplate struct {
	*WrappedElement
}

func (el *AutoBindGoTemplate) Bind(model BindInterface) {
	model.data().Element = el.WrappedElement

	refType := reflect.TypeOf(model)
	if refType.Kind() != reflect.Ptr || refType.Elem().Kind() != reflect.Struct {
		panic("BindInterface should be a pointer to a struct")
	}

	refVal := reflect.ValueOf(model).Elem()

	bindProtoField, found := refType.Elem().FieldByName("BindProto")
	if !found || !bindProtoField.Anonymous || bindProtoField.Type != typeOfPtrBindProto {
		panic("BindInterface should have an anonymous field polymer.BindProto")
	}

	// Set the BindProto
	refVal.FieldByIndex(bindProtoField.Index).Set(reflect.New(typeOfPtrBindProto.Elem()))

	jsObj := unwrap(el.Underlying())
	proto := lookupProto(jsObj).(*autoBindTemplate)

	if proto.Model != nil {
		panic("Model may only be bound once")
	}

	if model.data().this != nil {
		panic("model is already bound to another template")
	}

	// Setup handlers
	for _, handler := range parseHandlers(refType) {
		jsObj.Set(getJsName(handler.Name), eventHandlerCallback(handler.Func))
	}

	// Setup compute functions
	for _, handler := range parseComputes(refType) {
		jsObj.Set(getJsName(handler.Name), computeCallback(handler.Func))
	}

	// Setup channel based event handlers
	for _, handler := range parseChanHandlers(refType) {
		// Create channel
		chanVal := refVal.FieldByIndex(handler.Index)
		chanVal.Set(reflect.MakeChan(chanVal.Type(), 0))

		// Set handler function
		jsObj.Set(getJsName(handler.Name), eventChanCallback(chanVal))
	}

	// Set the needed data on Go side
	proto.Model = model
	model.data().this = jsObj
	proto.bound = true
	proto.render()

	// Notify the JS side
	proto.Notify("model")
}
<commit_msg>Fix a silly mistake related to dom-bind-go templates panicking<commit_after>package polymer

import (
	"github.com/gopherjs/gopherjs/js"
	"reflect"
)

var typeOfPtrBindProto = reflect.TypeOf(&BindProto{})

type BindInterface interface {
	Notify(path string)
	data() *BindProto
}

type BindProto struct {
	this *js.Object
	Element
}

func (p *BindProto) data() *BindProto { return p }
func (p *BindProto) Notify(path string) {
	lookupProto(p.data().this).data().Notify("model." + path)
}

type AutoBindGoTemplate struct {
	*WrappedElement
}

func (el *AutoBindGoTemplate) Bind(model BindInterface) {

	refType := reflect.TypeOf(model)
	if refType.Kind() != reflect.Ptr || refType.Elem().Kind() != reflect.Struct {
		panic("BindInterface should be a pointer to a struct")
	}

	refVal := reflect.ValueOf(model).Elem()

	bindProtoField, found := refType.Elem().FieldByName("BindProto")
	if !found || !bindProtoField.Anonymous || bindProtoField.Type != typeOfPtrBindProto {
		panic("BindInterface should have an anonymous field polymer.BindProto")
	}

	// Set the BindProto
	refVal.FieldByIndex(bindProtoField.Index).Set(reflect.New(typeOfPtrBindProto.Elem()))

	jsObj := unwrap(el.Underlying())
	proto := lookupProto(jsObj).(*autoBindTemplate)

	if proto.Model != nil {
		panic("Model may only be bound once")
	}

	if model.data().this != nil {
		panic("model is already bound to another template")
	}

	model.data().Element = el.WrappedElement

	// Setup handlers
	for _, handler := range parseHandlers(refType) {
		jsObj.Set(getJsName(handler.Name), eventHandlerCallback(handler.Func))
	}

	// Setup compute functions
	for _, handler := range parseComputes(refType) {
		jsObj.Set(getJsName(handler.Name), computeCallback(handler.Func))
	}

	// Setup channel based event handlers
	for _, handler := range parseChanHandlers(refType) {
		// Create channel
		chanVal := refVal.FieldByIndex(handler.Index)
		chanVal.Set(reflect.MakeChan(chanVal.Type(), 0))

		// Set handler function
		jsObj.Set(getJsName(handler.Name), eventChanCallback(chanVal))
	}

	// Set the needed data on Go side
	proto.Model = model
	model.data().this = jsObj
	proto.bound = true
	proto.render()

	// Notify the JS side
	proto.Notify("model")
}

{'fraction_non_alphanumeric': 0.13293741434444953, 'fraction_numerical': 0.00045682960255824577, 'mean_word_length': 4.716710182767624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5467747', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1405, 'n_words': 330}